1
00:00:00,300 --> 00:00:07,950
So as we have seen previously, an emperor can be seen as a victor or as matrix.

2
00:00:08,700 --> 00:00:15,510
So let us discuss a bit what we can do with these areas in terms of multiplying vectors, for example.

3
00:00:16,290 --> 00:00:23,100
So here I have written down two new vectors Vector one and Vector two, and they just contain some random

4
00:00:23,100 --> 00:00:23,550
numbers.

5
00:00:24,210 --> 00:00:25,380
So let us around the cell.

6
00:00:25,740 --> 00:00:32,369
And now what we can do is we can use the functions that are built into python or better to say, into

7
00:00:32,369 --> 00:00:37,860
Nampai, to calculate the Dot product and also with the cross product of these two vectors.

8
00:00:39,060 --> 00:00:43,230
So the DOT product is defined as and p dot.

9
00:00:43,500 --> 00:00:44,820
And then we typed Yochi.

10
00:00:46,330 --> 00:00:52,710
And if you dot of vector one comma factor two and the result is a nine.

11
00:00:53,490 --> 00:00:56,370
So in case you don't know how a dot product is calculated.

12
00:00:57,240 --> 00:01:02,220
Yeah, basically, you multiply these two numbers, plus the product of these two numbers, plus the

13
00:01:02,220 --> 00:01:03,300
product of these two numbers.

14
00:01:03,600 --> 00:01:07,440
So we have two plus three, which is five plus four is nine.

15
00:01:08,550 --> 00:01:17,430
Then we can also calculate the vector product or so-called cross product by typing NPR Dot Cross.

16
00:01:18,640 --> 00:01:25,890
Once again, we used a two arguments Vector one and Vector two, and the result will be an array.

17
00:01:26,100 --> 00:01:30,780
So a vector with a components one minus two and one.

18
00:01:32,220 --> 00:01:39,150
So I think you will notice, but a vector product does not commute.

19
00:01:39,240 --> 00:01:45,630
So this means the order in which we provide these arguments does matter for the results.

20
00:01:45,810 --> 00:01:51,180
So when I change this year to a vector to come, our vector one gives me a different result and gives

21
00:01:51,180 --> 00:01:52,650
me the opposite sign.

22
00:01:54,060 --> 00:01:58,800
So this means, of course, we will learn later how to define functions.

23
00:01:58,800 --> 00:02:02,550
And of course, you could say I want to define my own cross product function.

24
00:02:03,090 --> 00:02:10,139
Or you could also say, I want to define no function at all and just calculate all the components every

25
00:02:10,139 --> 00:02:11,550
time I use across product.

26
00:02:12,000 --> 00:02:12,620
That's OK.

27
00:02:12,630 --> 00:02:17,370
But that, of course, takes a bit more time than just using the command that is provided by.

28
00:02:19,080 --> 00:02:21,060
And also one more comment.

29
00:02:21,570 --> 00:02:28,770
Most of these non-player routines, they rely on other programming languages, and they are really optimized.

30
00:02:28,830 --> 00:02:34,740
So in terms of calculation time, so they are really, really fast to calculate and much faster than

31
00:02:34,740 --> 00:02:36,330
what we would do it ourselves.

32
00:02:37,770 --> 00:02:42,900
So another typical thing that you want to do with vectors is calculating their norm.

33
00:02:42,990 --> 00:02:44,730
So basically their length.

34
00:02:45,570 --> 00:02:48,990
So the command here is an p dot.

35
00:02:49,170 --> 00:02:56,990
And no, it's not just norm, but we first need to say it arc for linear algebra and then norm.

36
00:02:58,230 --> 00:03:03,390
So I cannot really tell you why this is the case, but this is what the command is and p fill in OG

37
00:03:03,600 --> 00:03:04,370
and more.

38
00:03:05,160 --> 00:03:11,400
And for example, for vector number two, the norm is some floating point number five point something.

39
00:03:12,690 --> 00:03:15,610
So as I mentioned, we don't have to use this function.

40
00:03:15,630 --> 00:03:17,070
We can also do it ourselves.

41
00:03:17,250 --> 00:03:25,890
So we could say the norm is calculated as the square root and p square root of the X component squared.

42
00:03:26,370 --> 00:03:32,760
So this would be Vector two and then in square brackets zero and the square would be this.

43
00:03:33,570 --> 00:03:42,840
And then we add the square of the Y component and the square of the Z component.

44
00:03:44,640 --> 00:03:52,160
And the result is exactly the same as when we were using the function that was provided by Nampai.

45
00:03:53,550 --> 00:03:54,540
So what else can we do?

46
00:03:55,110 --> 00:04:03,390
Well, we can also use another Nampai function, which is the and p some function, because we could

47
00:04:03,390 --> 00:04:09,280
just say, since our vector is an array, we can do component wise.

48
00:04:10,380 --> 00:04:12,000
Yeah, mathematical operations.

49
00:04:12,390 --> 00:04:19,920
So when I write factor two to the power of two, the result will be that every component of our vector.

50
00:04:20,130 --> 00:04:24,300
So this would be two three four will be squared.

51
00:04:24,510 --> 00:04:29,160
So the result will be an array with the components for nine and 16.

52
00:04:30,180 --> 00:04:34,110
So now what we have to do is we have to write and p got some.

53
00:04:36,750 --> 00:04:39,060
So this will add up these three numbers.

54
00:04:39,570 --> 00:04:42,390
So this would be exactly this one.

55
00:04:43,230 --> 00:04:48,750
And know we only have to write NPR Dot Square Root and we have our norm.

56
00:04:49,350 --> 00:04:52,440
So you see three different methods to calculate the norm.

57
00:04:52,450 --> 00:04:57,780
But of course, the most easy one is to just use to come on that is provided by Nampai and the Lindborg

58
00:04:58,410 --> 00:04:58,890
module.

59
00:05:00,420 --> 00:05:03,210
So that's all I wanted to say about vectors.

60
00:05:03,210 --> 00:05:07,350
Of course, people work with vectors in the following course and you will learn more about this.

61
00:05:07,710 --> 00:05:10,260
But these are just like the really the basics.

62
00:05:11,220 --> 00:05:14,430
So now let's continue and let's define some matrices.

63
00:05:15,240 --> 00:05:20,010
So as we have learned, a matrix is just a multidimensional array.

64
00:05:20,010 --> 00:05:30,540
So we write Mporei and the science is wrong, the normal brackets, and then we make one square brackets

65
00:05:30,540 --> 00:05:31,590
and then another one.

66
00:05:31,920 --> 00:05:33,690
And here we write the first line.

67
00:05:34,140 --> 00:05:36,510
So I just take some random numbers.

68
00:05:39,720 --> 00:05:42,210
Yeah, minus four or five and minus six.

69
00:05:43,170 --> 00:05:49,680
And another one, I don't know, seven, minus eight nine.

70
00:05:50,610 --> 00:05:57,780
And let's define also another matrix, which we could, for example, make diagonal or also.

71
00:05:57,810 --> 00:06:06,570
Yeah, maybe we do it like this one one one zero two two and zero zero three.

72
00:06:06,600 --> 00:06:09,960
So just some random numbers doesn't really matter so much.

73
00:06:10,920 --> 00:06:17,280
So and also we have seen that once we write, once we call these functions or of these functions, but

74
00:06:17,280 --> 00:06:22,860
these variables, then it gives us the output in such a matrix form, which is really nice.

75
00:06:23,910 --> 00:06:29,550
So what we can do with matrices is, of course, we can multiply them so we can write Matrix one times

76
00:06:29,550 --> 00:06:30,300
Matrix two.

77
00:06:31,260 --> 00:06:38,340
However, as we have learned, the and pitot array function, when you apply a mathematical operation,

78
00:06:38,730 --> 00:06:44,130
the operation will be applied to every component and the similar thing happens here.

79
00:06:44,820 --> 00:06:51,990
So when we look at our two matrices, you can see that the result here is just a component wise multiplication.

80
00:06:52,440 --> 00:06:56,310
So one times one is one minus two times one minus two.

81
00:06:56,640 --> 00:06:59,460
For example, here, five times two is 10.

82
00:07:00,390 --> 00:07:02,980
And this is not really how you multiply matrices.

83
00:07:03,000 --> 00:07:07,410
So this expression here is not really reasonable and not really useful.

84
00:07:08,070 --> 00:07:12,480
What we want instead is a matrix multiplication and the correct command.

85
00:07:12,480 --> 00:07:17,420
Here is and P dot match model for matrix multiplication.

86
00:07:17,880 --> 00:07:20,190
And then two arguments would be matrix one.

87
00:07:20,640 --> 00:07:21,900
And of course, Matrix two.

88
00:07:22,920 --> 00:07:25,260
This time we get the correct term.

89
00:07:25,860 --> 00:07:35,130
For example, the central number here would be the the dot product of these of this vector with this

90
00:07:35,130 --> 00:07:35,640
vector.

91
00:07:35,640 --> 00:07:42,630
So it would be minus four times one, which is minus four plus five times two, which is 10 and then

92
00:07:42,630 --> 00:07:44,580
plus minus six times zero, which is zero.

93
00:07:44,580 --> 00:07:49,170
So we have minus four plus 10, which is, of course, six.

94
00:07:49,710 --> 00:07:52,530
So you see, it really is a matrix multiplication.

95
00:07:53,550 --> 00:08:00,960
And we can also do is we can reverse the arguments and say, calculate the product of Matrix two and

96
00:08:00,960 --> 00:08:01,320
one.

97
00:08:01,710 --> 00:08:07,380
And of course, the result will be different because like the cross product for vectors, the matrix

98
00:08:07,380 --> 00:08:10,410
multiplication is not computing for the matrices.

99
00:08:11,520 --> 00:08:18,030
So another very important thing for matrices is calculating the determinant and also the inverse, which

100
00:08:18,120 --> 00:08:20,040
so these two operations are kind of related.

101
00:08:20,490 --> 00:08:32,039
So here we just use two commands and p dot linear algebra dot determinant Matrix two, for example,

102
00:08:32,400 --> 00:08:35,340
which has a matrix sorry, which has a determinant of six.

103
00:08:36,150 --> 00:08:52,860
And then we can also write and p dot linear algebra dot inverse, which is Matrix two or yeah, where

104
00:08:52,860 --> 00:08:55,560
we used to function on Matrix two.

105
00:08:56,550 --> 00:08:58,350
So what's the property of an inverse?

106
00:08:58,440 --> 00:09:07,980
Well, if you calculate the Matrix product so and p dot matrix multiplication of this matrix and the

107
00:09:07,980 --> 00:09:12,570
matrix itself, it gives us the one matrix.

108
00:09:12,720 --> 00:09:14,970
So just ones on the main diagonal.

109
00:09:16,140 --> 00:09:16,590
All right.

110
00:09:16,590 --> 00:09:23,010
So you see, we have calculated the the inverse, the determinant, and we have checked everything is

111
00:09:23,010 --> 00:09:23,430
correct.

112
00:09:24,240 --> 00:09:28,500
And of course, just a mathematical fact you will propose and notice.

113
00:09:29,040 --> 00:09:34,360
So if we calculate the inverse of Matrix one, we see something strange happened to you.

114
00:09:34,390 --> 00:09:35,430
We get very, very.

115
00:09:35,480 --> 00:09:42,020
Large numbers here for two to power so far, times 10 to the power of 15, so this doesn't seem reasonable.

116
00:09:42,030 --> 00:09:43,070
What is happening here?

117
00:09:43,460 --> 00:09:46,560
Well, the thing is the determinant of this number is zero.

118
00:09:46,580 --> 00:09:48,560
So there's just zero, basically.

119
00:09:49,640 --> 00:09:55,250
So if a determinant of a matrix is zero, then you cannot calculate the inverse, which gives us this

120
00:09:55,250 --> 00:09:55,940
problem here.

121
00:09:56,900 --> 00:10:03,020
So sometimes you have to be a bit careful because the correct mathematical output would have been the

122
00:10:03,020 --> 00:10:04,790
inverse of this matrix doesn't exist.

123
00:10:05,390 --> 00:10:08,490
But of course, since it's a computer that's a bit hard to do.

124
00:10:08,510 --> 00:10:11,660
So the result will just be some unreasonable number.

125
00:10:11,780 --> 00:10:14,690
So be a bit careful when you use these commands.

126
00:10:15,410 --> 00:10:20,870
But overall, working with matrices and vectors is pretty easy and pretty straightforward.

127
00:10:21,260 --> 00:10:26,840
You just have to be careful that all the ranks of fitting and sometimes you have to even transpose the

128
00:10:26,840 --> 00:10:27,610
matrices.

129
00:10:27,620 --> 00:10:33,950
And yeah, so that's as you note from mathematics so that this matrix multiplication works.

