So as we have seen previously, an emperor can be seen as a victor or as matrix.
So let us discuss a bit what we can do with these areas in terms of multiplying vectors, for example.
So here I have written down two new vectors Vector one and Vector two, and they just contain some random
numbers.
So let us around the cell.
And now what we can do is we can use the functions that are built into python or better to say, into
Nampai, to calculate the Dot product and also with the cross product of these two vectors.
So the DOT product is defined as and p dot.
And then we typed Yochi.
And if you dot of vector one comma factor two and the result is a nine.
So in case you don't know how a dot product is calculated.
Yeah, basically, you multiply these two numbers, plus the product of these two numbers, plus the
product of these two numbers.
So we have two plus three, which is five plus four is nine.
Then we can also calculate the vector product or so-called cross product by typing NPR Dot Cross.
Once again, we used a two arguments Vector one and Vector two, and the result will be an array.
So a vector with a components one minus two and one.
So I think you will notice, but a vector product does not commute.
So this means the order in which we provide these arguments does matter for the results.
So when I change this year to a vector to come, our vector one gives me a different result and gives
me the opposite sign.
So this means, of course, we will learn later how to define functions.
And of course, you could say I want to define my own cross product function.
Or you could also say, I want to define no function at all and just calculate all the components every
time I use across product.
That's OK.
But that, of course, takes a bit more time than just using the command that is provided by.
And also one more comment.
Most of these non-player routines, they rely on other programming languages, and they are really optimized.
So in terms of calculation time, so they are really, really fast to calculate and much faster than
what we would do it ourselves.
So another typical thing that you want to do with vectors is calculating their norm.
So basically their length.
So the command here is an p dot.
And no, it's not just norm, but we first need to say it arc for linear algebra and then norm.
So I cannot really tell you why this is the case, but this is what the command is and p fill in OG
and more.
And for example, for vector number two, the norm is some floating point number five point something.
So as I mentioned, we don't have to use this function.
We can also do it ourselves.
So we could say the norm is calculated as the square root and p square root of the X component squared.
So this would be Vector two and then in square brackets zero and the square would be this.
And then we add the square of the Y component and the square of the Z component.
And the result is exactly the same as when we were using the function that was provided by Nampai.
So what else can we do?
Well, we can also use another Nampai function, which is the and p some function, because we could
just say, since our vector is an array, we can do component wise.
Yeah, mathematical operations.
So when I write factor two to the power of two, the result will be that every component of our vector.
So this would be two three four will be squared.
So the result will be an array with the components for nine and 16.
So now what we have to do is we have to write and p got some.
So this will add up these three numbers.
So this would be exactly this one.
And know we only have to write NPR Dot Square Root and we have our norm.
So you see three different methods to calculate the norm.
But of course, the most easy one is to just use to come on that is provided by Nampai and the Lindborg
module.
So that's all I wanted to say about vectors.
Of course, people work with vectors in the following course and you will learn more about this.
But these are just like the really the basics.
So now let's continue and let's define some matrices.
So as we have learned, a matrix is just a multidimensional array.
So we write Mporei and the science is wrong, the normal brackets, and then we make one square brackets
and then another one.
And here we write the first line.
So I just take some random numbers.
Yeah, minus four or five and minus six.
And another one, I don't know, seven, minus eight nine.
And let's define also another matrix, which we could, for example, make diagonal or also.
Yeah, maybe we do it like this one one one zero two two and zero zero three.
So just some random numbers doesn't really matter so much.
So and also we have seen that once we write, once we call these functions or of these functions, but
these variables, then it gives us the output in such a matrix form, which is really nice.
So what we can do with matrices is, of course, we can multiply them so we can write Matrix one times
Matrix two.
However, as we have learned, the and pitot array function, when you apply a mathematical operation,
the operation will be applied to every component and the similar thing happens here.
So when we look at our two matrices, you can see that the result here is just a component wise multiplication.
So one times one is one minus two times one minus two.
For example, here, five times two is 10.
And this is not really how you multiply matrices.
So this expression here is not really reasonable and not really useful.
What we want instead is a matrix multiplication and the correct command.
Here is and P dot match model for matrix multiplication.
And then two arguments would be matrix one.
And of course, Matrix two.
This time we get the correct term.
For example, the central number here would be the the dot product of these of this vector with this
vector.
So it would be minus four times one, which is minus four plus five times two, which is 10 and then
plus minus six times zero, which is zero.
So we have minus four plus 10, which is, of course, six.
So you see, it really is a matrix multiplication.
And we can also do is we can reverse the arguments and say, calculate the product of Matrix two and
one.
And of course, the result will be different because like the cross product for vectors, the matrix
multiplication is not computing for the matrices.
So another very important thing for matrices is calculating the determinant and also the inverse, which
so these two operations are kind of related.
So here we just use two commands and p dot linear algebra dot determinant Matrix two, for example,
which has a matrix sorry, which has a determinant of six.
And then we can also write and p dot linear algebra dot inverse, which is Matrix two or yeah, where
we used to function on Matrix two.
So what's the property of an inverse?
Well, if you calculate the Matrix product so and p dot matrix multiplication of this matrix and the
matrix itself, it gives us the one matrix.
So just ones on the main diagonal.
All right.
So you see, we have calculated the the inverse, the determinant, and we have checked everything is
correct.
And of course, just a mathematical fact you will propose and notice.
So if we calculate the inverse of Matrix one, we see something strange happened to you.
We get very, very.
Large numbers here for two to power so far, times 10 to the power of 15, so this doesn't seem reasonable.
What is happening here?
Well, the thing is the determinant of this number is zero.
So there's just zero, basically.
So if a determinant of a matrix is zero, then you cannot calculate the inverse, which gives us this
problem here.
So sometimes you have to be a bit careful because the correct mathematical output would have been the
inverse of this matrix doesn't exist.
But of course, since it's a computer that's a bit hard to do.
So the result will just be some unreasonable number.
So be a bit careful when you use these commands.
But overall, working with matrices and vectors is pretty easy and pretty straightforward.
You just have to be careful that all the ranks of fitting and sometimes you have to even transpose the
matrices.
And yeah, so that's as you note from mathematics so that this matrix multiplication works.