Notes@HKU by Jax

Matrices

Matrices are represented by capitial letters: ARr×cA\in R^{r\times c}. r×cr \times c are the dimensions of a given matrix

Basic operations

Addition

Matrices can perform per-element addition if their dimensions match.

[123456]+[654321]=[777777]\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix} + \begin{bmatrix} 6 & 5 & 4 \\ 3 & 2 & 1 \end{bmatrix} = \begin{bmatrix} 7 & 7 & 7 \\7 & 7 & 7 \end{bmatrix}

Scalar multiplication

Matrices can perform per-element multiplication with a scalar.

[123321]×2=[246642]\begin{bmatrix} 1 & 2 & 3 \\3 & 2 & 1 \end{bmatrix} \times 2 = \begin{bmatrix} 2 & 4 & 6 \\6 & 4 & 2 \end{bmatrix}

Matrix-matrix multiplication

Matrices can only multiply if their inner dimensions match, otherwise there will be no solution.

If a matrix is multiplied by another matrix, each element in the result matrix is the sum of it's corresponding row in the original matrix performing per-element multiplication on it's corresponding col in the applying matrix

[1234]×[1234]=[11+2312+2431+4332+44]=[7101522]\begin{bmatrix} 1 & 2 \\3 & 4 \end{bmatrix} \times \begin{bmatrix} 1 & 2 \\3 & 4 \end{bmatrix}=\begin{bmatrix} 1\cdot 1 + 2 \cdot 3 & 1\cdot 2 + 2\cdot 4 \\3\cdot 1 + 4\cdot 3&3\cdot 2 + 4\cdot 4 \end{bmatrix} = \begin{bmatrix} 7 & 10 \\15 & 22 \end{bmatrix}

Transposition

The function ATA^T transposes the matrix AA. It swaps the rows and columns of a matrix.

[1234]T[1324][123]T[123]\begin{bmatrix} 1 & 2 \\3&4 \end{bmatrix}^T \equiv \begin{bmatrix} 1 & 3 \\2&4 \end{bmatrix}\quad \begin{bmatrix} 1 & 2 & 3 \end{bmatrix}^T \equiv \begin{bmatrix} 1 \\2\\3 \end{bmatrix}

Solving linear systems

Identity matrix

The identity matrix of IRn×nI\in \mathbb{R}^{n\times n} with square dimensions is the matrix with diagonal elements of 1 and others 0.

IR3×3=[100010001]I\in \mathbb{R}^{3\times 3}=\begin{bmatrix} 1 & 0 & 0 \\0&1&0\\0&0&1 \end{bmatrix}

Row-echelon form

A matrix with a bottom-left or top-right triangle of 0's (excluding the diagonal) is considered to be in row-echelon form.

[123012001] and [100120001]\begin{bmatrix} 1 & 2 & 3 \\0&1&2\\0&0&1 \end{bmatrix}\text{ and }\begin{bmatrix} 1 & 0 & 0 \\1&2&0\\0&0&1 \end{bmatrix} are both considered in row-echelon form

Augmented Matrix and Gaussian Elimination

Augmented matrices are an important tool to solve linear equations. The number of rows is equal to the number of variables in the equation.

GE are operations by rows, performed on augmented matrices. The possible moves are:

  1. Addition between rows (R1+R2R_1 + R_2 adds row 2 to row 1, leaving row 2 unchanged)
  2. Multiplication of a row by a scalar (12R1\frac{1}{2}R_1)
  3. Swapping rows (R1R2R_1\leftrightarrow R_2)

Strict variables

Consider the following linear system. We can take the coefficients and write it into AM form as followed:

x1+2x2=32x1+5x2=10[1232x15x210] \begin{matrix} x_1 + 2x_2 = 3 \\ 2x_1 + 5x_2 = 10 \end{matrix}\xRightarrow{\hspace{0.5cm}} \left[\begin{array}{cc|c} 1 & 2 & 3 \\ \underbrace{2}_{x_1} & \underbrace{5}_{x_2} & 10 \end{array}\right]

Then, we perform GE on the created augmented matrix to make the left side row-echelon.

[1232510]R22R1[123014] \left[\begin{array}{cc|c} 1 & 2 & 3 \\ 2 & 5 & 10 \end{array}\right] \xrightarrow{R_2-2R_1} \left[\begin{array}{cc|c} 1 & 2 & 3 \\ 0 & 1 & 4 \end{array}\right]

Deriving from the AM, we know:

x1+2x2=3x2=4 \begin{matrix} x_1 + 2x_2 = 3 \\ x_2 = 4 \end{matrix}

So the solution is:

[3244][54] \begin{bmatrix} 3-2\cdot 4 \\ 4 \end{bmatrix}\equiv \begin{bmatrix} -5 \\ 4 \end{bmatrix}

Inconsistent systems

We say a system is inconsistent if a full row of 0 on the left is equal to a non-zero number. We can also conclude that there are no solutions to the system. The following is an example of a system with no solutions:

x1+2x2=32x1+4x2=10[1232410]R22R1[123004] \begin{matrix} x_1 + 2x_2 = 3 \\ 2x_1 + 4x_2 = 10 \end{matrix}\xRightarrow{\hspace{0.5cm}} \left[\begin{array}{cc|c} 1 & 2 & 3 \\ 2 & 4 & 10 \end{array}\right]\xrightarrow{R_2-2R_1} \left[\begin{array}{cc|c} 1 & 2 & 3 \\ \htmlClass{text-red-500}{0} & \htmlClass{text-red-500}{0} & \htmlClass{text-red-500}{4} \end{array}\right]

Free variable systems

Free variables are variables with their corresponding columns having no leading 1s before 0s in the augmented matrix. If a system has free variables, the solution exists in a space, defined by the general solution.

Consider the following system with free variables, we can derive:

[105083014106000free0free10]x15x3+8x5=3x24x3x4=6x5=0 \left[\begin{array}{cccc|c} 1 & 0 & \htmlClass{text-blue-500}{-5} & \htmlClass{text-blue-500}{0} & 8 & 3 \\ 0 & 1 & \htmlClass{text-blue-500}{-4} & \htmlClass{text-blue-500}{-1} & 0 & 6 \\ 0 & 0 & \htmlClass{text-blue-500}{\underbrace{0}_{free}} & \htmlClass{text-blue-500}{\underbrace{0}_{free}} & 1 & 0 \end{array}\right]\xRightarrow{\hspace{0.5cm}}\begin{matrix} x_1 -5x_3+8x_5 = 3 \\ x_2-4x_3-x_4=6 \\ x_5=0 \end{matrix}

We can ignore the free variables, and substitute x5x_5 into both equations, deriving the general solution to be:

x=[3+5x36+x4+4x3x3x40] x=\begin{bmatrix} 3+5x_3 \\ 6+x_4+4x_3 \\ x_3 \\ x_4 \\ 0 \end{bmatrix}

Matrix determinant

Determinant is a property of a matrix, represented by A\|A\| or det(A)det(A). Only square matrices have a determinant.

Finding the value of determinant

The determinant of a 2 times 2 matrix

forA=[abcd],A=adbcfor\quad A=\begin{bmatrix} a & b \\c&d \end{bmatrix},\quad |A| = ad - bc

The determinant of a n times n matrix

Choose any row or column, then for each element, ignore their corresponding row and column to give the co-factor of the element.

det(A)=(a×det(co-factor)×(1)ra+ca)det(A) = \sum(a\times det(\text{co-factor})\times (-1)^{r_a+c_a})

Where aa is an element from the picked row or column, and racar_a c_a are the row and column number of a

123111321=1112121131+31132=0|\begin{smallmatrix}1&2&3\\1&1&1\\3&2&1\end{smallmatrix}|=1|\begin{smallmatrix} 1&1\\2&1 \end{smallmatrix}|-2|\begin{smallmatrix} 1&1\\3&1 \end{smallmatrix}|+3|\begin{smallmatrix} 1&1\\3&2 \end{smallmatrix}|=0

Determinant of row-echelon form matrices

Product of diagonal elements. 123023003=123=6|\begin{smallmatrix} 1&2&3\\0&2&3\\0&0&3 \end{smallmatrix}|=1\cdot 2\cdot 3=6

  1. Vector dependency
  2. Matrix inverse
  3. Matrix eigenpairs

Vectors

Vectors are matrices with a single column, represented by letters with an arrow above them. v=[123]\overrightarrow{v} = \begin{bmatrix} 1 \\2\\3 \end{bmatrix}

Dot product

The dot product of two vectors a\vec{a} and b\vec{b} is essentially aTb\vec{a}^T\cdot\vec{b}

Vector length

v\|\|\vec{v}\|\| gives the length of a vector. [ab]T=a2+b2+||\begin{bmatrix} a & b & \dots \end{bmatrix}^T||=\sqrt[]{a^2 + b^2 + \dots}

Unit vectors

They are vectors with the length of one. vv\frac{\vec{v}}{\|\|\vec{v}\|\|} transforms the vector to a unit vector.

Vector dependency

If v1v2=0|\begin{smallmatrix} v_1 & v_2 & \dots \end{smallmatrix}|=0, the vectors are dependent of each other

Orthogonal projection

The orthogonal projection of aa onto bb is projba=(aTbbTb)bproj_ba = (\frac{a^Tb}{b^Tb})b.

The component of aa perpendicular to bb is given by aprojbaa-proj_ba

Orthonormal matrices

Orthonormal matrices have vector columns length 1, and which any product of two vectors is 0. For an orthonormal matrix AA, AAT=IAA^T = I

Expressing a vector as a linear combination

We can express a vector v\vec{v} as the linear combination of other vectors a,b,a, b, \dots by:

v=projav+projbv+v = proj_av + proj_bv + \dots

Vector spans

Vectors have the same span if they are linearly dependent

The dimension of span(A)span(A) is given by the number of non-zero rows after GE

Matrix inverse

Inverse is a property and function of a matrix, represented by A1A^{-1}

Matrix inversibility

The matrix has an inverse if A0\|A\|\ne 0, and that it is a square matrix.

Finding the inverse of a 2 times 2 matrix

A1=1A[dbca]A^{-1} = \frac{1}{|A|}\begin{bmatrix} d & -b \\-c &a \end{bmatrix}

Finding the inverse of a n times n matrix

[AI]GE[IA1]\left[\begin{array}{c|c} A & I \end{array}\right]\xrightarrow{GE}\left[\begin{array}{c|c} I & A^{-1} \end{array}\right]

Matrix eigenpairs

Matrices have properties eigenvalues λn\lambda_n and eigenvectors vnv_n. They must satisfy the condition Av=λvAv=\lambda v, and has the following properties:

  1. λn\lambda_n and vnv_n come in pairs (each value correspond to a vector)
  2. Matrices can only have λ1,λ2λn\lambda_1, \lambda_2 \dots \lambda_n where nn is the smallest dimension of the matrix
  3. An vnv_n includes all vectors of its multiple, and is non-zero By convention, λ1>λ2>>λn\lambda_1 > \lambda_2 > \dots > \lambda_n

Solving for eigenvalues

Note that we can rearrange the condition to (AIλ)v=0(A-I\lambda)v=0, and into AIλ=0\|A-I\lambda\| = 0. Rearrange into polynomial equation and solve for λ\lambda by first trial and error (if degree >2> 2) and then factorization.

The eigenvalues of [1141]\begin{bmatrix} 1 & 1 \\4&1 \end{bmatrix} can be found by 1λ141λ=0:(1λ)24=0λ1=3, λ2=1|\begin{smallmatrix} 1-\lambda&1\\4&1-\lambda \end{smallmatrix}|=0:\quad(1-\lambda)^2 - 4 = 0\quad\rightarrow\quad\lambda_1=3,\ \lambda_2=-1

Algebratic and Geometric Multiplicity

AM is the number of times the value of λ\lambda occur (e.g. (1λ)2=0,λ1=1(1-\lambda)^2=0, \lambda_1=1 has AM=2AM=2)

GM is the size of nullspace (line of 0s) when plugging λ\lambda into (AIλ)v=0(A-I\lambda)v=0

Solving for eigenvectors

Plug each λ\lambda into (AIλ)v=0(A-I\lambda)v=0, perform GE, then let the deterministic variable(s) as 1.

For λ1=3\lambda_1=3 and A=[111111111]A=\begin{bmatrix} 1 & 1 & 1 \\1&1&1\\1&1&1 \end{bmatrix}:

(A3λ)v=0[211012101120]GE[211001100000]  GM=1(A-3\lambda)v=0 \xRightarrow{\hspace{0.5cm}} \left[\begin{array}{ccc|c} -2 & 1 & 1 & 0 \\1&-2&1&0\\1&1&-2&0 \end{array}\right]\xrightarrow{GE}\left[\begin{array}{ccc|c} -2 & 1 & 1 & 0 \\0&-1&1&0\\\htmlClass{text-blue-500}{0}&\htmlClass{text-blue-500}{0}&\htmlClass{text-blue-500}{0}&\htmlClass{text-blue-500}{0} \end{array}\right]\begin{matrix} \ \\\ \\\htmlClass{text-blue-500}{GM=1} \end{matrix}

From the augmented matrix: 2x1+x2+x3=0,x2+x3=0-2x_1+x_2+x_3=0,\quad -x_2+x_3=0.

As x3x_3 is in both equations, let x3=1x_3=1: x2=1,x1=1v1=[111]x_2=1, x_1=1\rightarrow v_1=\begin{bmatrix}1 \\1\\1\end{bmatrix}

Solving for eigenvectors with GM 2

Find the other eigenvector with v=z2projz1z2v = z_2 - proj_{z_1}z_2

For v=[x22x3x2x3]v=\begin{bmatrix} -x_2-2x_3 \\x_2\\x_3 \end{bmatrix}, find the two solution forms as z1=[110], z2[201]z_1=\begin{bmatrix} -1 \\1\\0 \end{bmatrix},\ z_2\begin{bmatrix} -2 \\0\\1 \end{bmatrix}

Then let z1=v1z_1=v_1, and solve for v2v_2 with v2=z2projz1z2=[201]2+0+01+1+0[110]v_2=z_2-proj_{z_1}z_2=\begin{bmatrix}-2 \\0\\1\end{bmatrix} - \frac{2+0+0}{1+1+0}\begin{bmatrix}-1 \\1\\0\end{bmatrix}

Related properties:

  1. Diag
  2. Quad
  3. Diff

Matrix diagonalization

Condition

A matrix can only be diagonalized if all of it's eigenpairs has their AM=GMAM = GM.

Eigendecomposition

A=VDV1,where V=[v1vn], D=[λ1000000λn]A=VDV^{-1},\quad\text{where }V=\begin{bmatrix}v_1 \\\dots\\v_n\end{bmatrix},\ D=\begin{bmatrix}\lambda_1 & 0 & 0 \\0&\ddots&0\\0&0&\lambda_n\end{bmatrix}

We can also derive Ak=VDkV1A^k=VD^kV^{-1}

Differential equations

Given x(0)x(0), solve for x(t)x(t) with the following steps:

  1. Solve for eigenpairs
  2. xk=cveλt++cveλtxk = cve^{\lambda t} + \dots + cve^{\lambda t}
  3. Solve c by augmented matrix [v1vnx(0)]\left[\begin{array}{ccc|c}v_1 & \dots & v_n & x(0)\end{array}\right]

Quadratic form

A quadratic equation can be written into the form Q(x)=xAxTQ(x)=xAx^T, where AA is a symmetric matrix.

Symmetric matrices

A matrix is symmetric if A=ATA=A^T

Linear to matrix quadratic

Q(x)=ax12+bx22+cx32+dx1x2+ex2x3+fx1x3=[x1x2x3][ad2f2d2be2f2e2c][x1x2x3]\begin{aligned} Q(x) & =ax_1^2+bx_2^2+cx_3^2+dx_1x_2+ex_2x_3+fx_1x_3 \\ & =\begin{bmatrix} x_1 & x_2 & x_3 \end{bmatrix}\begin{bmatrix} a & \frac{d}{2} & \frac{f}{2} \\\frac{d}{2}&b&\frac{e}{2}\\\frac{f}{2}&\frac{e}{2}&c \end{bmatrix}\begin{bmatrix} x_1 \\x_2\\x_3 \end{bmatrix} \end{aligned}

Definitiveness of a quadratic

For Q(x)=xAxTQ(x)=xAx^T, considering the eigenvalues of AA:

  • Q(x)Q(x) is positive definitive if λ>0\forall\lambda > 0
  • Q(x)Q(x) is negative definitive if λ<0\forall\lambda < 0
  • Q(x)Q(x) is indefinite if otherwise
  • Q(x)Q(x) is p/n semi-definitive if the conditions are inclusive (i.e. λor0\lambda \geq or \leq 0)

Minimum and maximum values

λmax=max{xAxT:x=1}\lambda_{max} = max\{xAx^T:\|\|x\|\|=1\}

λmin=min{xAxT:x=1}\lambda_{min} = min\{xAx^T:\|\|x\|\|=1\}

Apply the corresponding vxv\rightarrow x to find the min/max of Q(x)Q(x). Note that x=1\|\|x\|\|=1 is a required restriction on Q(x)Q(x), otherwise its size would be infinite.

On this page