• A matrix is a rectangular array of numbers written between square brackets. A matrix is just another way for saying, is a 2D or a two dimensional array. The dimension of the matrix is going to be written as the number of row times the number of columns in the matrix.


  • matrices and vectors


  • Matrices and Vectors


    1. Matrices are 2-dimensional arrays:


    2. \( \begin{bmatrix} a & b & c \newline d & e & f \newline g & h & i \newline j & k & l\end{bmatrix} \)


    3. The above matrix has four rows and three columns, so it is a 4 x 3 matrix.


    4. A vector is a matrix with one column and many rows:


    5. \( \begin{bmatrix} w \newline x \newline y \newline z \end{bmatrix} \)


    6. So vectors are a subset of matrices. The above vector is a 4 x 1 matrix.


  • Notation and terms:


    1. \( A_{ij} \) - refers to the element in the ith row and jth column of matrix A.


    2. A vector with 'n' rows is referred to as an 'n'-dimensional vector.


    3. \( v_iv \)- refers to the element in the ith row of the vector.


    4. In general, all our vectors and matrices will be 1-indexed. Note that for some programming languages, the arrays are 0-indexed.


    5. Matrices are usually denoted by uppercase names while vectors are lowercase.


    6. "Scalar" means that an object is a single value, not a vector or matrix.


    7. \( \mathbb{R} \) refers to the set of scalar real numbers.


    8. \( \mathbb{R^n} \) refers to the set of n-dimensional vectors of real numbers.


  • Addition and Scalar Multiplication


    1. Addition and subtraction are element-wise, so you simply add or subtract each corresponding element:


    2. \( \begin{bmatrix} a & b \newline c & d \newline \end{bmatrix} +\begin{bmatrix} w & x \newline y & z \newline \end{bmatrix} =\begin{bmatrix} a+w & b+x \newline c+y & d+z \newline \end{bmatrix} \)


  • Subtracting Matrices:


    1. \( \begin{bmatrix} a & b \newline c & d \newline \end{bmatrix} - \begin{bmatrix} w & x \newline y & z \newline \end{bmatrix} =\begin{bmatrix} a-w & b-x \newline c-y & d-z \newline \end{bmatrix} \)


    2. To add or subtract two matrices, their dimensions must be the same.


    3. In scalar multiplication, we simply multiply every element by the scalar value:


    4. \( \begin{bmatrix} a & b \newline c & d \newline \end{bmatrix} * x =\begin{bmatrix} a*x & b*x \newline c*x & d*x \newline \end{bmatrix} \)


    5. In scalar division, we simply divide every element by the scalar value:


    6. \( \begin{bmatrix} a & b \newline c & d \newline \end{bmatrix} / x =\begin{bmatrix} a /x & b/x \newline c /x & d /x \newline \end{bmatrix} \)


  • Matrix-Vector Multiplication


    1. We map the column of the vector onto each row of the matrix, multiplying each element and summing the result


    2. \( \begin{bmatrix} a & b \newline c & d \newline e & f \end{bmatrix} *\begin{bmatrix} x \newline y \newline \end{bmatrix} =\begin{bmatrix} a*x + b*y \newline c*x + d*y \newline e*x + f*y\end{bmatrix} \)


    3. The result is a vector. The number of columns of the matrix must equal the number of rows of the vector.


    4. An m x n matrix multiplied by an n x 1 vector results in an m x 1 vector.


  • Matrix-Matrix Multiplication


    1. We multiply two matrices by breaking it into several vector multiplications and concatenating the result.


    2. \( \begin{bmatrix} a & b \newline c & d \newline e & f \end{bmatrix} *\begin{bmatrix} w & x \newline y & z \newline \end{bmatrix} =\begin{bmatrix} a*w + b*y & a*x + b*z \newline c*w + d*y & c*x + d*z \newline e*w + f*y & e*x + f*z\end{bmatrix} \)


    3. An m x n matrix multiplied by an n x o matrix results in an m x o matrix. In the above example, a 3 x 2 matrix times a 2 x 2 matrix resulted in a 3 x 2 matrix.


    4. To multiply two matrices, the number of columns of the first matrix must equal the number of rows of the second matrix.


  • Matrix Multiplication Properties


    1. Matrices are not commutative: \( A∗B \neq B∗A \)


    2. Matrices are associative: \( (A∗B)∗C = A∗(B∗C) \)


    3. The identity matrix, when multiplied by any matrix of the same dimensions, results in the original matrix. It's just like multiplying numbers by 1. The identity matrix simply has 1's on the diagonal (upper left to lower right diagonal) and 0's elsewhere.


    4. \( \begin{bmatrix} 1 & 0 & 0 \newline 0 & 1 & 0 \newline 0 & 0 & 1 \newline \end{bmatrix} \)


    5. When multiplying the identity matrix after some matrix (A∗I), the square identity matrix's dimension should match the other matrix's columns. When multiplying the identity matrix before some other matrix (I∗A), the square identity matrix's dimension should match the other matrix's rows


  • Inverse and Transpose


    1. The inverse of a matrix A is denoted \( A^{-1} \)


    2. Multiplying by the inverse results in the identity matrix.


    3. A non square matrix does not have an inverse matrix. We can compute inverses of matrices in octave with the pinv(A) function and in Matlab with the inv(A) function. Matrices that don't have an inverse are singular or degenerate.


    4. The transposition of a matrix is like rotating the matrix 90° in clockwise direction and then reversing it. We can compute transposition of matrices in matlab with the transpose(A) function or A':


    5. \( A = \begin{bmatrix} a & b \newline c & d \newline e & f \end{bmatrix} \)


    6. \( A^T = \begin{bmatrix} a & c & e \newline b & d & f \newline \end{bmatrix} \)


    7. In other words: \( A_{ij} = A_{ji}^T \)