Mathematical guide/Matrix operations: Difference between revisions
m VectorGraphics moved page Mathematical guide/Matrix multiplication to Mathematical guide/Matrix operations |
No edit summary |
||
Line 1: | Line 1: | ||
== Dot product == | |||
A vector is a list of numbers, written like so: <math> \begin{pmatrix} | |||
-2\\ | |||
0\\ | |||
1 | |||
\end{pmatrix} </math>. | |||
The dot product is a way to combine two vectors to get out a single number. | |||
Say we want to take the dot product of the vectors <math> \begin{pmatrix}12\\19\\28\end{pmatrix} </math> and <math> \begin{pmatrix}-2\\0\\1\end{pmatrix} </math>. | |||
To do so, follow these steps: | |||
* Write the vectors separated by a dot to denote the dot product: <math> | |||
\begin{pmatrix} | |||
12\\ | |||
19\\ | |||
28\\ | |||
\end{pmatrix} | |||
\cdot | |||
\begin{pmatrix} | |||
-2\\ | |||
0\\ | |||
1 | |||
\end{pmatrix} | |||
</math> | |||
**This may also be notated <math> \langle 12, 19, 28 \vert -2, 0, 1\rangle </math>; from this derives the notation for vals and monzos. | |||
* Multiply the corresponding elements, and add the results together: <math> \left(12\cdot-2\right)+\left(19\cdot0\right)+\left(28\cdot1\right) = -24 + 0 + 28 = 4 </math> | |||
== Multiply matrix by vector == | |||
A matrix is a grid of numbers, written like so: | |||
<math> | |||
\begin{bmatrix} | |||
1 & 0 & -4\\ | |||
0 & 1 & 4 | |||
\end{bmatrix} | |||
</math> | |||
This matrix can be thought of as a "function" that you apply to a vector to get out another vector. This matrix has 3 columns, meaning the vector it takes as an "input" will have 3 elements, and it has 2 rows, meaning the vector you get out will have 2 elements. So, this is a "function" down from 3-dimensional space to 2-dimensional space. | |||
We write this "application" of a matrix like so: | |||
<math> | |||
\begin{bmatrix} | |||
1 & 0 & -4\\ | |||
0 & 1 & 4 | |||
\end{bmatrix} | |||
\begin{bmatrix} | |||
-2\\ | |||
0\\ | |||
1 | |||
\end{bmatrix} | |||
</math> | |||
where the second object is the vector. | |||
To write the first element of our output, we take the dot product of the first row of our matrix with our vector: | |||
<math>\begin{pmatrix} | |||
1\\ | |||
0\\ | |||
-4\\ | |||
\end{pmatrix} | |||
\cdot | |||
\begin{pmatrix} | |||
-2\\ | |||
0\\ | |||
1 | |||
\end{pmatrix} | |||
= \left(1\cdot-2\right)+\left(0\cdot0\right)+\left(-4\cdot1\right) = -2 + 0 + -4 = -6 </math> | |||
We do the same thing for the second element of our output, computing <math> | |||
\begin{pmatrix} | |||
0\\ | |||
1\\ | |||
4\\ | |||
\end{pmatrix} | |||
\cdot | |||
\begin{pmatrix} | |||
-2\\ | |||
0\\ | |||
1 | |||
\end{pmatrix} | |||
= 4 | |||
</math>. | |||
Thus, our output is <math> \begin{bmatrix} | |||
-6\\ | |||
4\\ | |||
\end{bmatrix}</math> | |||
. | |||
== Multiply matrix by matrix == | |||
A matrix can act on another matrix, as well. In this case, the matrix on the right can simply be treated as several vectors next to each other. | |||
<math> | |||
\begin{bmatrix} | |||
1 & 0 & -4\\ | |||
0 & 1 & 4 | |||
\end{bmatrix} | |||
\begin{bmatrix} | |||
1 & -1 & -2\\ | |||
0 & 1 & 0\\ | |||
0 & 0 & 1 | |||
\end{bmatrix} | |||
= | |||
\begin{bmatrix} | |||
1 & -1 & -6\\ | |||
0 & 1 & 4 | |||
\end{bmatrix} | |||
</math> |