Matrix
- Tags
- math
A Matrix is a rectangular array of numbers, such as \( \begin{pmatrix} 1 & 2 \\ 3 & 4\end{pmatrix} \).
Arithmetic Operations
Addition and subtraction of two matrices is an element-wise operation and can only be done when both matrices shares the same shape. Multiplying or dividing by a scalar applies the multiplication to all the elements of the matrix.
The key operation when working with matrices is multiplication between two matrices. This is a \( \text{row} \times \text{column} \) operation; meaning when multiplying a matrix \( A \) with a matrix \( B \) each cell of the output matrix uses a row from \( A \) and a column from \( B \).
\begin{align*} \begin{pmatrix}
\text{\nth{1} row, \nth{1} column} & \text{\nth{1} row, \nth{2} column} & \text{\nth{1} row, \ldots column} \\\\
\text{\nth{2} row, \nth{1} column} & \text{\nth{2} row, \nth{2} column} & \text{\nth{2} row, \ldots column} \\\\
\text{\ldots row, \nth{1} column} & \text{\ldots row, \nth{2} column} & \text{\ldots row, \ldots column} \\\\
\end{pmatrix} \end{align*}
The actual operation used to combine rows and columns is a dot-product, meaning we multiply each element of the row with each element of the column and then sum all the numbers to get a cell value. The output matrix will have the same number of rows as the left-hand matrix and the same number of columns as the right-hand matrix.
Demonstration of Matrix Multiplication example
Consider the matrices:
\begin{align*} A =&
\begin{pmatrix}
1 & 2 & 3 \\\\
4 & 5 & 6
\end{pmatrix} \\\\
B =&
\begin{pmatrix}
1 & 4 \\\\
2 & 5 \\\\
3 & 6
\end{pmatrix}
\end{align*}
Observe that \(A\) has dimensions \( M \times N = 2 \times 3 \) and \(B\) has dimensions \( X \times Y = 3 \times 2 \). Note: \( Y = N \), and this must be the case if we wish to do \( A \times B \).
Now consider:
\begin{align*} A \times B =&
\begin{pmatrix}
1 & 2 & 3 \\\\
4 & 5 & 6
\end{pmatrix}
\times
\begin{pmatrix}
1 & 4 \\\\
2 & 5 \\\\
3 & 6
\end{pmatrix} \\\\
& \begin{pmatrix}
(1 \times 1) + (2 \times 2) + (3 \times 3) & (1 \times 4) + (2 \times 5) + (3 \times 6) \\\\
(4 \times 1) + (5 \times 2) + (6 \times 3) & (4 \times 4) + (5 \times 5) + (6 \times 6)
\end{pmatrix} \
&
\begin{pmatrix}
14 & 32 \\\\
32 & 77
\end{pmatrix} \end{align*}
Observe that we've multiplied a \( M \times N \) matrix by a \( X \times Y \) matrix and ended up with a \( M \times Y \) matrix. We have the same number of rows as our left hand matrix and the same number of columns as our right hand matrix.
Multiplication Non-Commutativity example
Matrix multiplication is non-commutative, meaning the order in which the two matrices are multiplied is relevant. For example consider:
\begin{align} S &=
\begin{pmatrix}
0 & 1 \\\\
-1 & 0
\end{pmatrix} \\\\
T &=
\begin{pmatrix}
1 & 1 \\\\
0 & 1
\end{pmatrix} \\\\
ST &=
\begin{pmatrix}
0 & 1 \\\\
-1 & -1
\end{pmatrix} \\\\
TS &=
\begin{pmatrix}
-1 & 1 \\\\
-1 & 0
\end{pmatrix} \\\\
ST &\neq TS \end{align}
Matrix Algebra examples
Using the rules of matrix arithmetic we can solve algebraic problems like the following:
\begin{align}
AB \times (AB)^{-1} &= I \
A^{-1} \times AB \times (AB)^{-1} &= A^{-1} I \
I \times B \times (AB)^{-1} &= A^{-1} \
B \times (AB)^{-1} &= A^{-1} \
\
B^{-1} \times B \times (AB)^{-1} &= B^{-1} \times A^{-1} \
I \times (AB)^{-1} &= B^{-1} \times A{-1} \
(AB)^{-1} &= B^{-1} A^{-1}
\end{align}
\begin{align}
ABC &= I \
A^{-1} ABC C^{-1} &= A^{-1} I C^{-1} \
B &= A^{-1} C^{-1} \
B^{-1} &= (A^{-1} C{-1}){-1}
\end{align}