Vector - A vector is a matrix where either the width or the height is 1. When the height is 1, it's called a row vector. When the width is 1 it's called a column vector.
Matrix Element - The element in the first row and first column of the matrix given above is the number $1.5$
Square Matrix - A matrix is square when its height is equal to its width.
The numbers $i$ and $j$ are used to refer to the row number and column number of a matrix (respectively).
NOTE: The top left element of a matrix is typically given by $\mathbf{A}_{11}$ and not $\mathbf{A}_{00}$.**
In [ ]:
# python demo
A = [
["A_1,1", "A_1,2", "A_1,3"],
["A_2,1", "A_2,2", "A_2,3"],
["A_3,1", "A_3,2", "A_3,3"],
["A_4,1", "A_4,2", "A_4,3"],
]
print("the bottom right entry in the A matrix is:", A[3][2])
Summation is best described by example.
$$\sum_{i=1}^n a_{nn}$$This equation can be read as "The sum from i equals one to n of the matrix element at row $n$, column $n$."
When you see $\sum$ you should think "for loop". The code below demonstrates the following mathematical equation:
$$\sum_{i=1}^n \sum_{j=1}^m a_{ij}$$
In [ ]:
def sum_all_matrix_elements(A):
"""
Computes the sum of ALL elements in some matrix A.
"""
n = len(A)
m = len(A[0])
total = 0.0
for i in range(n):
for j in range(m):
total = total + A[i][j]
return total
example_matrix = [
[1, 3, 5],
[4, 2, 2],
]
print(sum_all_matrix_elements(example_matrix))
Matrix addition and subtraction is an element by element operation. Two matrices must have the same dimensions in order to be added or subtracted.
$$\mathbf{A} + \mathbf{B} = \begin{bmatrix} a_{11} & a_{12} & \dots & a_{1n}\\ a_{21} & a_{22} & \dots &a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn} \end{bmatrix} + \begin{bmatrix} b_{11} & b_{12} & \dots & b_{1n}\\ b_{21} & b_{22} & \dots &b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ b_{m1} & b_{m2} & \dots & b_{mn} \end{bmatrix}$$$$= \begin{bmatrix} a_{11}+b_{11} & a_{12}+b_{12} & \dots & a_{1n}+b_{1n}\\ a_{21}+b_{21} & a_{22}+b_{22} & \dots & a_{2n}+b_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1}+b_{m1} & a_{m2}+b_{m2} & \dots & a_{mn}+b_{mn} \end{bmatrix}$$When multiplying a matrix $\mathbf{A}$ by a scalar $c$, all of the entries in $\mathbf{A}$ are multiplied by $c$:
$$c\mathbf{A} = c \begin{bmatrix}a_{11} & a_{12} & \dots & a_{1n}\\ a_{21} & a_{22} & \dots &a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \dots & a_{mn} \end{bmatrix} = \begin{bmatrix} ca_{11} & ca_{12} & \dots & ca_{1n}\\ ca_{21} & ca_{22} & \dots &ca_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ ca_{m1} & ca_{m2} & \dots & ca_{mn}\end{bmatrix}$$Multiplication of Matrix $\mathbf{A}$ with matrix $\mathbf{B}$ is only possible if the width of $\mathbf{A}$ is equal to the height of $\mathbf{B}$
If $\mathbf{A}$ is an $m \times n$ matrix and $\mathbf{B}$ is an $n \times p$ matrix, their product $\mathbf{AB}$ is an $m \times p$ matrix.
When multiplying two matrices, we can calculate the value of the element at row $i$ and column $j$ with the following equation:
$$(\mathbf{AB})_{ij} = \sum_{k=1}^n a_{ik}b_{kj}$$The transpose of a matrix $\mathbf{A}$ is given by $\mathbf{A^T}$ and can be thought of in several ways:
Mathematically, the element at row $i$ and column $j$ of the transpose is given by:
$$[\mathbf{A^T}]_{ij} = [\mathbf{A}]_{ji}$$The trace of an $n\times n$ square matrix $\mathbf{A}$ is the sum of the elements on the main diagonal of the matrix.
$$\text{tr}\left(\mathbf{A}\right) = \sum_{i=1}^n a_{ii} = a_{11} + a_{22} + \dots + a_{nn}$$The determinant is a useful value when describing a matrix. It can be denoted in one of three ways:
1x1 Matrices
The determinant of a $1\times1$ matrix is just the value of the matrice's only element. For example if $\mathbf{A} = \begin{vmatrix}4\end{vmatrix}$, then the determinant of $\mathbf{A}$ is given by:
$$\begin{vmatrix}\mathbf{A}\end{vmatrix} = 4$$2x2 Matrices
The determinant of a $2\times2$ matrix is given by:
$$\begin{vmatrix}\mathbf{A}\end{vmatrix} = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc $$Larger Matrices
You will not be required to calculate the determinant for larger matrices. If you are interested in learning more you should look at the Wikipedia article: Determinant.
The inverse of a matrix $\mathbf{A}$ is given by $\mathbf{A^{-1}}$
A matrix $\mathbf{A}$ is invertible if there exists a matrix $\mathbf{B}$ such that the product of $\mathbf{A}$ and $\mathbf{B}$ is the identity matrix $\mathbf{I}$:
$$\mathbf{AB} = \mathbf{BA} = \mathbf{I}$$1x1 Matrices
For a $1\times1$ matrix with a single element with value $a$, the inverse is simlpy $\frac{1}{a}$
2x2 Matrices
The inverse of a $2\times 2$ matrix is given by the following equation:
$$\mathbf{A}^{-1} = \frac{1}{\text{det }\mathbf{A}} \left[\left(\text{tr } \mathbf{A}\right) \mathbf{I} - \mathbf{A}\right]$$Larger Matrices
You will not be required to invert larger matrices. If you are interested in learning more you should look at the Wikipedia article Invertible Matrix.
In [ ]: