Reference sheet

Linear Algebra I reference sheet

The main definitions, formulas, theorems and algorithms of Linear Algebra I on one page, unit by unit, with links to the lessons that explain each topic in full.

For Linear Algebra I

This sheet follows the eleven units of the course in order. Each unit starts with the big idea in a few sentences, then gives the definitions, formulas, theorems and algorithms you will look up most often, with the conditions they need. When you want the full explanation, a proof or more examples, follow the lesson links under each topic.

Scalars are real numbers until complex numbers enter in the unit on eigenvalues. Vectors are columns and get bold lowercase letters such as v\mathbf{v}, with the zero vector 0\mathbf{0} and the standard unit vectors e1,…,en\mathbf{e}_1, \dots, \mathbf{e}_n. In running text a tuple such as (3,−1)(3, -1) stands for the column with those entries. Vectors of an abstract vector space are bold too, while a polynomial pp or a matrix used as a vector keeps its usual name. Scalars are plain italic letters, matrices are capitals such as AA, and a real m×nm \times n matrix is a map from Rn\mathbb{R}^n to Rm\mathbb{R}^m. The transpose is A⊤A^{\top}, the dot product is x⋅y=x⊤y\mathbf{x} \cdot \mathbf{y} = \mathbf{x}^{\top}\mathbf{y}, the norm is ∥x∥\lVert \mathbf{x} \rVert and a general inner product is ⟨u,v⟩\langle \mathbf{u}, \mathbf{v} \rangle.

A matrix has the subspaces Col⁡A\operatorname{Col} A, Row⁡A\operatorname{Row} A and Null⁡A\operatorname{Null} A, and a linear map TT has ker⁡T\ker T and im⁡T\operatorname{im} T. An ordered basis is B=(b1,…,bn)\mathcal{B} = (\mathbf{b}_1, \dots, \mathbf{b}_n), the coordinate column of v\mathbf{v} in it is [v]B[\mathbf{v}]_{\mathcal{B}}, and coordinates change by [v]C=PC←B[v]B[\mathbf{v}]_{\mathcal{C}} = P_{\mathcal{C} \leftarrow \mathcal{B}}[\mathbf{v}]_{\mathcal{B}}. The characteristic polynomial is χA(t)=det⁡(tI−A)\chi_A(t) = \det(tI - A), eigenvalues come in no particular order, and singular values are nonnegative and listed in decreasing order. For complex matrices A∗=A‾⊤A^{*} = \overline{A}^{\top} and ⟨x,y⟩=x∗y\langle \mathbf{x}, \mathbf{y} \rangle = \mathbf{x}^{*}\mathbf{y}, which is conjugate-linear in the first argument. Row operations are written as R2→R2−3R1R_2 \to R_2 - 3R_1. A formula holds wherever both sides are defined unless a condition says otherwise.

Vectors and Matrices

Vectors are lists of numbers that can be added and scaled, and matrices collect vectors as columns. Multiplying a matrix by a vector forms a weighted sum of its columns. Linear transformations are the maps that respect addition and scaling, and composing two of them multiplies their matrices in a definite order.

Vectors and linear combinations

A vector in Rn\mathbb{R}^n is an ordered list of nn real numbers. Vectors of the same size are added and scaled entry by entry,

u+v=[u1+v1⋮un+vn],cv=[cv1⋮cvn].\begin{gathered} \mathbf{u} + \mathbf{v} = \begin{bmatrix} u_1 + v_1 \\ \vdots \\ u_n + v_n \end{bmatrix}, \\[0.4em] c\mathbf{v} = \begin{bmatrix} c v_1 \\ \vdots \\ c v_n \end{bmatrix}. \end{gathered}

In the plane and in space a sum follows the tip-to-tail rule, and for v≠0\mathbf{v} \ne \mathbf{0} the multiple cvc\mathbf{v} points along v\mathbf{v} when c>0c > 0 and against it when c<0c < 0, with ∣c∣\lvert c \rvert times the length. A point PP is a location, while the displacement from PP to QQ is the vector Q−PQ - P, endpoint minus starting point, wherever its arrow is drawn. A data vector lists measurements in a fixed order, and a sum of two data vectors means something only when matching positions hold the same quantity in the same unit.

A linear combination of v1,…,vk\mathbf{v}_1, \dots, \mathbf{v}_k is a1v1+⋯+akvka_1\mathbf{v}_1 + \cdots + a_k\mathbf{v}_k with real coefficients, and span⁡{v1,…,vk}\operatorname{span}\{\mathbf{v}_1, \dots, \mathbf{v}_k\} is the set of all of them. It always contains 0\mathbf{0}. A vector b\mathbf{b} lies in the span exactly when the system x1v1+⋯+xkvk=bx_1\mathbf{v}_1 + \cdots + x_k\mathbf{v}_k = \mathbf{b} has a solution. A generator that is a combination of the others is redundant, and removing it leaves the span unchanged.

For example a(1,0,1)+b(0,1,1)=(a,b,a+b)a(1, 0, 1) + b(0, 1, 1) = (a, b, a + b), so these two vectors span the plane z=x+yz = x + y in R3\mathbb{R}^3. The vector (2,−1,1)(2, -1, 1) equals 2(1,0,1)−(0,1,1)2(1, 0, 1) - (0, 1, 1), while (2,−1,0)(2, -1, 0) is not in the span, because its third entry is not the sum of the first two.

Lessons Vectors and Vector Operations, Linear Combinations and Span

Matrices and the matrix-vector product

An m×nm \times n matrix A=[aij]A = [a_{ij}] has mm rows and nn columns a1,…,an\mathbf{a}_1, \dots, \mathbf{a}_n in Rm\mathbb{R}^m, and the entry aija_{ij} sits in row ii and column jj. For x\mathbf{x} in Rn\mathbb{R}^n,

Ax=x1a1+x2a2+⋯+xnan,A\mathbf{x} = x_1\mathbf{a}_1 + x_2\mathbf{a}_2 + \cdots + x_n\mathbf{a}_n,

a vector in Rm\mathbb{R}^m whose entry ii is row ii times x\mathbf{x}, that is ai1x1+⋯+ainxna_{i1}x_1 + \cdots + a_{in}x_n. The product needs exactly nn entries in x\mathbf{x}.

OperationDefinitionCondition
Sum(A+B)ij=aij+bij(A + B)_{ij} = a_{ij} + b_{ij}same size
Scalar multiple(cA)ij=c aij(cA)_{ij} = c\,a_{ij}any real cc
Transpose(A⊤)ij=aji(A^{\top})_{ij} = a_{ji}, an n×mn \times m matrixany size
Product rules(A+B)x=Ax+Bx(A + B)\mathbf{x} = A\mathbf{x} + B\mathbf{x} and (cA)x=c(Ax)(cA)\mathbf{x} = c(A\mathbf{x})same size

Transposing twice gives (A⊤)⊤=A(A^{\top})^{\top} = A, and (A+B)⊤=A⊤+B⊤(A + B)^{\top} = A^{\top} + B^{\top}. The transpose only rearranges entries, and in general it is not the inverse of AA. The 2×32 \times 3 matrix

A=[101011],A⊤=[100111],\begin{gathered} A = \begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 1 \end{bmatrix}, \\[0.4em] A^{\top} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \end{bmatrix}, \end{gathered}

returns several times on this sheet, always under the name AA. It maps R3\mathbb{R}^3 to R2\mathbb{R}^2, and

A[2−13]=2[10]−[01]+3[11]=[52].\begin{aligned} A\begin{bmatrix} 2 \\ -1 \\ 3 \end{bmatrix} &= 2\begin{bmatrix} 1 \\ 0 \end{bmatrix} - \begin{bmatrix} 0 \\ 1 \end{bmatrix} + 3\begin{bmatrix} 1 \\ 1 \end{bmatrix} \\[0.4em] &= \begin{bmatrix} 5 \\ 2 \end{bmatrix}. \end{aligned}

Lessons Matrices and Matrix-Vector Multiplication

Linear transformations

A map TT from Rn\mathbb{R}^n to Rm\mathbb{R}^m is linear when, for all u\mathbf{u} and v\mathbf{v} in Rn\mathbb{R}^n and every real cc,

T(u+v)=T(u)+T(v),T(cu)=c T(u).\begin{gathered} T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v}), \\[0.4em] T(c\mathbf{u}) = c\,T(\mathbf{u}). \end{gathered}

These are additivity and homogeneity, and together they say that TT keeps every linear combination, T(au+bv)=aT(u)+bT(v)T(a\mathbf{u} + b\mathbf{v}) = aT(\mathbf{u}) + bT(\mathbf{v}). Every linear map has T(0)=0T(\mathbf{0}) = \mathbf{0}, but a map that fixes 0\mathbf{0} need not be linear.

Standard matrix. A linear TT is multiplication by exactly one m×nm \times n matrix, the one whose columns are the images of the standard unit vectors,

A=[T(e1)⋯T(en)],T(x)=Ax.\begin{gathered} A = \begin{bmatrix} T(\mathbf{e}_1) & \cdots & T(\mathbf{e}_n) \end{bmatrix}, \\[0.4em] T(\mathbf{x}) = A\mathbf{x}. \end{gathered}

Conversely every map x↦Ax\mathbf{x} \mapsto A\mathbf{x} is linear. Two linear maps that agree on e1,…,en\mathbf{e}_1, \dots, \mathbf{e}_n agree everywhere.

The shear H(x,y)=(x+y,y)H(x, y) = (x + y, y) has H(e1)=(1,0)H(\mathbf{e}_1) = (1, 0) and H(e2)=(1,1)H(\mathbf{e}_2) = (1, 1), which are the columns of its matrix. A translation x↦x+b\mathbf{x} \mapsto \mathbf{x} + \mathbf{b} with b≠0\mathbf{b} \ne \mathbf{0} is not linear, since it moves 0\mathbf{0}. The map G(x,y)=(x2,y)G(x, y) = (x^2, y) fixes 0\mathbf{0} and is still not linear, because G(2,0)=(4,0)G(2, 0) = (4, 0) while 2G(1,0)=(2,0)2G(1, 0) = (2, 0). One failed identity proves that a map is not linear, and no number of successful spot checks proves that it is.

Lessons Linear Transformations

Matrix multiplication and composition

If AA is m×nm \times n and BB is n×pn \times p with columns b1,…,bp\mathbf{b}_1, \dots, \mathbf{b}_p, then ABAB is the m×pm \times p matrix

AB=[Ab1⋯Abp],(AB)ij=∑k=1naikbkj.\begin{gathered} AB = \begin{bmatrix} A\mathbf{b}_1 & \cdots & A\mathbf{b}_p \end{bmatrix}, \\[0.4em] (AB)_{ij} = \sum_{k=1}^{n} a_{ik}b_{kj}. \end{gathered}

It is defined only when AA has as many columns as BB has rows. It is the matrix of the composition that applies BB first and then AA, so (AB)x=A(Bx)(AB)\mathbf{x} = A(B\mathbf{x}).

RuleStatementCondition
Associativity(AB)C=A(BC)(AB)C = A(BC)compatible sizes
DistributivityA(B+C)=AB+ACA(B + C) = AB + AC and (A+B)C=AC+BC(A + B)C = AC + BCcompatible sizes
IdentityImA=A=AInI_m A = A = A I_nAA is m×nm \times n
Transpose of a product(AB)⊤=B⊤A⊤(AB)^{\top} = B^{\top}A^{\top}ABAB defined, and the order reverses
OrderAB≠BAAB \ne BA in generalBABA may be undefined or of another size

Block multiplication. When the column groups of AA match the row groups of BB, the product can be formed block by block, with block (i,j)(i, j) of ABAB equal to ∑kAikBkj\sum_k A_{ik}B_{kj}. Each block product keeps its order.

For the shear matrix HH above and D=diag⁡(2,1)D = \operatorname{diag}(2, 1),

DH=[2201],HD=[2101],\begin{gathered} DH = \begin{bmatrix} 2 & 2 \\ 0 & 1 \end{bmatrix}, \\[0.4em] HD = \begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix}, \end{gathered}

so shearing first and then stretching sends e2\mathbf{e}_2 to (2,1)(2, 1), while stretching first sends it to (1,1)(1, 1).

Lessons Matrix Multiplication and Composition

Systems of Linear Equations

A linear system asks for every input that satisfies several linear equations at once. Row operations simplify a system without changing its solutions, and pivots and free variables then describe all of them. A square matrix with a pivot in every column has an inverse, and the LU factorization stores elimination so that it can be reused for new right-hand sides.

Linear systems and their two pictures

A system of mm linear equations in nn unknowns is one matrix equation Ax=bA\mathbf{x} = \mathbf{b}, with an m×nm \times n coefficient matrix AA, unknowns x\mathbf{x} in Rn\mathbb{R}^n and right-hand side b\mathbf{b} in Rm\mathbb{R}^m. Its augmented matrix is [ A∣b ][\,A \mid \mathbf{b}\,].

  • Row picture. Each equation describes the set of points of Rn\mathbb{R}^n that satisfy it, which is a line, plane or hyperplane when its coefficients are not all zero. The solution set is the intersection of all these sets.
  • Column picture. The system asks for weights with x1a1+⋯+xnan=bx_1\mathbf{a}_1 + \cdots + x_n\mathbf{a}_n = \mathbf{b}, so it is consistent exactly when b\mathbf{b} lies in the span of the columns.

Every linear system has no solution, exactly one, or infinitely many, because if p≠q\mathbf{p} \ne \mathbf{q} are solutions, so is every p+t(q−p)\mathbf{p} + t(\mathbf{q} - \mathbf{p}). A square coefficient matrix does not by itself guarantee one solution, and more equations than unknowns do not rule out infinitely many.

For example x+y=3x + y = 3 and x−y=1x - y = 1 meet at (2,1)(2, 1), and in the column picture 2(1,1)+1(1,−1)=(3,1)2(1, 1) + 1(1, -1) = (3, 1). The pair x+y=2x + y = 2 and 2x+2y=42x + 2y = 4 has the whole line of solutions (t,2−t)(t, 2 - t), and the pair x+y=2x + y = 2 and 2x+2y=52x + 2y = 5 has none.

Lessons Linear Systems as Equations and Geometry

Row operations and Gaussian elimination

OperationNotationUndone by
Swap two rowsRi↔RjR_i \leftrightarrow R_jthe same swap
Scale a rowRi→cRiR_i \to cR_i with c≠0c \ne 0Ri→1cRiR_i \to \frac{1}{c}R_i
Row replacementRi→Ri+cRjR_i \to R_i + cR_j with i≠ji \ne jRi→Ri−cRjR_i \to R_i - cR_j

Each operation acts on whole rows of [ A∣b ][\,A \mid \mathbf{b}\,], constants included, and can be undone, so row equivalent augmented matrices have the same solution set. Applying an operation to ImI_m gives an elementary matrix EE, and EAEA performs that operation on AA. Operations E1,…,EkE_1, \dots, E_k applied in that order give Ek⋯E1AE_k \cdots E_1 A.

A matrix is in row echelon form when its zero rows are at the bottom, each leading entry lies strictly to the right of the leading entry above it, and every entry below a leading entry is zero. Its leading entries are the pivots. Gaussian elimination reaches an echelon form column by column, swapping in a nonzero pivot when needed and clearing the entries below it. Back-substitution then solves from the last equation upward.

For x+y+z=6x + y + z = 6, 2x+3y+z=112x + 3y + z = 11 and x+2y+3z=14x + 2y + 3z = 14, the augmented matrix

[11162311112314]\left[\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 2 & 3 & 1 & 11 \\ 1 & 2 & 3 & 14 \end{array}\right]

becomes, after R2→R2−2R1R_2 \to R_2 - 2R_1 and R3→R3−R1R_3 \to R_3 - R_1 and then R3→R3−R2R_3 \to R_3 - R_2,

[111601−1−10039].\left[\begin{array}{ccc|c} 1 & 1 & 1 & 6 \\ 0 & 1 & -1 & -1 \\ 0 & 0 & 3 & 9 \end{array}\right].

Back-substitution gives z=3z = 3, then y=−1+z=2y = -1 + z = 2, then x=6−y−z=1x = 6 - y - z = 1, and (1,2,3)(1, 2, 3) satisfies all three original equations.

Lessons Gaussian Elimination and Row Operations

Pivots, free variables and all solutions

The pivot columns of AA are the columns that hold pivots in an echelon form, and the unknowns of the other columns are free variables. The reduced row echelon form also has every pivot equal to 11 and zeros above each pivot, and every matrix has exactly one.

Echelon form of [ A∣b ][\,A \mid \mathbf{b}\,]Solutions
a row [ 0 ⋯ 0∣c ][\,0 \ \cdots \ 0 \mid c\,] with c≠0c \ne 0none
no such row, every column of AA a pivot columnexactly one
no such row, some column of AA without a pivotinfinitely many, one parameter for each free variable

A consistent system with nn unknowns and rr pivots has k=n−rk = n - r free variables. Every solution is one particular solution xp\mathbf{x}_p plus a solution of the homogeneous system Ax=0A\mathbf{x} = \mathbf{0}. Setting each free variable equal to its own parameter and solving for the pivot variables gives the complete solution family

x=xp+t1v1+⋯+tkvk,\mathbf{x} = \mathbf{x}_p + t_1\mathbf{v}_1 + \cdots + t_k\mathbf{v}_k,

with one real parameter tit_i for each free variable and fixed vectors vi\mathbf{v}_i that satisfy Avi=0A\mathbf{v}_i = \mathbf{0}. For the 2×32 \times 3 matrix AA and b=(4,3)\mathbf{b} = (4, 3), the third unknown is free, and setting x3=tx_3 = t gives

x=[430]+t[−1−11],t∈R.\mathbf{x} = \begin{bmatrix} 4 \\ 3 \\ 0 \end{bmatrix} + t\begin{bmatrix} -1 \\ -1 \\ 1 \end{bmatrix}, \qquad t \in \mathbb{R}.

Coefficient parameters. A letter among the coefficients selects a system, while a free variable selects a solution within one system. Dividing by an expression in the parameter is valid only where it is nonzero, so each value where it vanishes is solved again from the equations before the division. For

[111a]x=[23],\begin{bmatrix} 1 & 1 \\ 1 & a \end{bmatrix}\mathbf{x} = \begin{bmatrix} 2 \\ 3 \end{bmatrix},

the replacement R2→R2−R1R_2 \to R_2 - R_1 leaves (a−1)x2=1(a - 1)x_2 = 1. For a≠1a \ne 1 the unique solution is

x1=2a−3a−1,x2=1a−1.x_1 = \frac{2a - 3}{a - 1}, \qquad x_2 = \frac{1}{a - 1}.

For a=1a = 1 the row reads 0=10 = 1 and there is no solution. Check every answer in the original equations, with the parameter kept as a letter.

Lessons Pivots, Free Variables and All Solutions, Linear Systems with Parameters, Linear Systems Workshop

Inverse matrices

An n×nn \times n matrix AA is invertible when some n×nn \times n matrix A−1A^{-1} satisfies A−1A=IA^{-1}A = I and AA−1=IAA^{-1} = I. The inverse is unique, and a square matrix without one is singular. For an n×nn \times n matrix AA the following statements are equivalent.

  • The matrix AA has nn pivots.
  • The system Ax=bA\mathbf{x} = \mathbf{b} has exactly one solution for every b\mathbf{b} in Rn\mathbb{R}^n, namely x=A−1b\mathbf{x} = A^{-1}\mathbf{b}.
  • The only solution of Ax=0A\mathbf{x} = \mathbf{0} is x=0\mathbf{x} = \mathbf{0}.
  • The matrix AA is invertible.
RuleCondition
(AB)−1=B−1A−1(AB)^{-1} = B^{-1}A^{-1}AA and BB invertible of the same size
(A⊤)−1=(A−1)⊤(A^{\top})^{-1} = (A^{-1})^{\top}AA invertible
(cA)−1=1cA−1(cA)^{-1} = \frac{1}{c}A^{-1}AA invertible and c≠0c \ne 0

For a 2×22 \times 2 matrix with ad−bc≠0ad - bc \ne 0,

[abcd]−1=1ad−bc[d−b−ca].\begin{bmatrix} a & b \\ c & d \end{bmatrix}^{-1} = \frac{1}{ad - bc}\begin{bmatrix} d & -b \\ -c & a \end{bmatrix}.

Computing an inverse. Row reduce [ A∣I ][\,A \mid I\,]. If the left block becomes II, the right block is A−1A^{-1}, and if an echelon form of AA has fewer than nn pivots, then AA is singular. To solve a single system, eliminating on [ A∣b ][\,A \mid \mathbf{b}\,] takes less work than forming A−1A^{-1}.

For example

[2143]−1=12[3−1−42],\begin{bmatrix} 2 & 1 \\ 4 & 3 \end{bmatrix}^{-1} = \frac{1}{2}\begin{bmatrix} 3 & -1 \\ -4 & 2 \end{bmatrix},

and this inverse sends (5,11)(5, 11) to (2,1)(2, 1), the solution of the system with right-hand side (5,11)(5, 11).

Lessons Inverse Matrices and Invertibility

LU factorization

Suppose Gaussian elimination reduces a square matrix AA to an upper triangular UU without row swaps, working through the columns from left to right and applying Ri→Ri−ℓijRjR_i \to R_i - \ell_{ij}R_j to each row i>ji > j in column jj. Then

A=LU,A = LU,

where LL is unit lower triangular, with ones on the diagonal and the multiplier ℓij\ell_{ij} in position (i,j)(i, j). To solve Ax=bA\mathbf{x} = \mathbf{b}, solve Lw=bL\mathbf{w} = \mathbf{b} by forward substitution and then Ux=wU\mathbf{x} = \mathbf{w} by back-substitution. The factors are computed once and reused for every new right-hand side.

When a zero or small pivot calls for row swaps, the factorization reads PA=LUPA = LU with a permutation matrix PP, the identity with its rows reordered, which satisfies P−1=P⊤P^{-1} = P^{\top}. Then solve Lw=PbL\mathbf{w} = P\mathbf{b} and Ux=wU\mathbf{x} = \mathbf{w}. The swaps reorder equations, never unknowns, and a swap made after some multipliers are stored moves those multipliers with their rows. Partial pivoting takes as pivot an entry of largest absolute value in the current column, on or below the current row, so every multiplier has absolute value at most 11. A zero in a pivot position does not by itself make AA singular.

For example

[2143]=[1021][2101]\begin{bmatrix} 2 & 1 \\ 4 & 3 \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix}\begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix}

with the multiplier ℓ21=2\ell_{21} = 2. For b=(5,11)\mathbf{b} = (5, 11), forward substitution gives w=(5,1)\mathbf{w} = (5, 1) and back-substitution gives x=(2,1)\mathbf{x} = (2, 1), and the same factors solve the system with b=(1,1)\mathbf{b} = (1, 1), giving (1,−1)(1, -1).

Lessons LU Factorization and Pivoting

Vector Spaces

A subspace is a set of vectors that contains 0\mathbf{0} and is closed under addition and scaling. Linear independence makes coefficients unique, a basis is an independent list that spans, and the dimension counts the vectors in any basis. Every matrix has four fundamental subspaces, and elimination finds a basis of each.

Subspaces

A subset WW of Rn\mathbb{R}^n is a subspace when

  • it contains 0\mathbf{0},
  • the sum u+v\mathbf{u} + \mathbf{v} lies in WW for all u\mathbf{u} and v\mathbf{v} in WW, and
  • the multiple cuc\mathbf{u} lies in WW for every u\mathbf{u} in WW and every real cc.

A nonempty subset that is closed under both operations already contains 0=0u\mathbf{0} = 0\mathbf{u}. To prove that a set is a subspace, check these conditions for arbitrary members, and to prove that it is not, give one failure.

SetSubspaceReason
span⁡{v1,…,vk}\operatorname{span}\{\mathbf{v}_1, \dots, \mathbf{v}_k\}yessums and multiples of combinations are combinations
solutions of Ax=0A\mathbf{x} = \mathbf{0}yesA(u+cv)=Au+cAvA(\mathbf{u} + c\mathbf{v}) = A\mathbf{u} + cA\mathbf{v}
solutions of Ax=bA\mathbf{x} = \mathbf{b} with b≠0\mathbf{b} \ne \mathbf{0}no0\mathbf{0} is not a solution
U∩VU \cap V and U+V={u+v∣u∈U, v∈V}U + V = \{\mathbf{u} + \mathbf{v} \mid \mathbf{u} \in U,\ \mathbf{v} \in V\}yes, for subspaces UU and VVclosure holds in each piece
U∪VU \cup Vonly when U⊆VU \subseteq V or V⊆UV \subseteq Ua sum can leave the union

A translate p+W\mathbf{p} + W of a subspace is an affine set, and it is a subspace only when p\mathbf{p} lies in WW. The solution set of a consistent system Ax=bA\mathbf{x} = \mathbf{b} is the affine set xp+{x∣Ax=0}\mathbf{x}_p + \{\mathbf{x} \mid A\mathbf{x} = \mathbf{0}\}.

The plane z=x+yz = x + y is a subspace of R3\mathbb{R}^3, and the parallel plane z=x+y+1z = x + y + 1 is not, since it misses 0\mathbf{0}. The union of the two coordinate axes of R2\mathbb{R}^2 is not a subspace, because (1,0)+(0,1)(1, 0) + (0, 1) leaves it. For U=span⁡{e1,e2}U = \operatorname{span}\{\mathbf{e}_1, \mathbf{e}_2\} and V=span⁡{e1,e3}V = \operatorname{span}\{\mathbf{e}_1, \mathbf{e}_3\} in R3\mathbb{R}^3, the intersection is span⁡{e1}\operatorname{span}\{\mathbf{e}_1\} and the sum is R3\mathbb{R}^3.

Lessons Subspaces, Sums and Intersections

Linear independence

A list v1,…,vk\mathbf{v}_1, \dots, \mathbf{v}_k is linearly independent when

c1v1+⋯+ckvk=0  ⟹  c1=⋯=ck=0,\begin{aligned} &c_1\mathbf{v}_1 + \cdots + c_k\mathbf{v}_k = \mathbf{0} \\[0.4em] &\quad \implies c_1 = \cdots = c_k = 0, \end{aligned}

and dependent otherwise. A combination with coefficients not all zero that equals 0\mathbf{0} is a dependence relation.

  • An independent list gives unique coefficients. Every vector of its span is a combination of the list in exactly one way.
  • A list of two or more vectors is dependent exactly when one of its vectors is a combination of the others.
  • A list that contains 0\mathbf{0} is dependent, and two vectors are dependent exactly when one is a multiple of the other.
  • More than nn vectors in Rn\mathbb{R}^n are always dependent.

Test by elimination. Put the vectors in the columns of a matrix and row reduce. They are independent exactly when every column has a pivot. A column without a pivot gives a free variable, and setting it to 11 produces a dependence relation.

The vectors (1,0,1)(1, 0, 1), (0,1,1)(0, 1, 1) and (1,1,2)(1, 1, 2) are dependent, with the relation (1,0,1)+(0,1,1)−(1,1,2)=0(1, 0, 1) + (0, 1, 1) - (1, 1, 2) = \mathbf{0}, even though no two of them are parallel.

Lessons Linear Independence

Bases and dimension

A basis of a subspace WW is a list of vectors in WW that is linearly independent and spans WW, so every vector of WW is a combination of the list in exactly one way. For an ordered basis B=(b1,…,bk)\mathcal{B} = (\mathbf{b}_1, \dots, \mathbf{b}_k), the coordinate vector [v]B=(c1,…,ck)[\mathbf{v}]_{\mathcal{B}} = (c_1, \dots, c_k) lists the coefficients in v=c1b1+⋯+ckbk\mathbf{v} = c_1\mathbf{b}_1 + \cdots + c_k\mathbf{b}_k. It has one entry for each basis vector, and reordering the basis reorders the coordinates. The standard basis (e1,…,en)(\mathbf{e}_1, \dots, \mathbf{e}_n) of Rn\mathbb{R}^n gives each vector its own entries as coordinates.

  • Dimension. All bases of WW have the same number of vectors, dim⁡W\dim W. In WW an independent list has at most dim⁡W\dim W vectors and a spanning list has at least dim⁡W\dim W. The zero subspace has dimension 00, and a subspace of Rn\mathbb{R}^n has dim⁡W≤n\dim W \le n, with equality only for W=RnW = \mathbb{R}^n.
  • Pruning and extending. Removing, one at a time, a vector that is a combination of the remaining ones shrinks a spanning list to a basis. Adding, one at a time, a vector that lies outside the current span grows an independent list to a basis.
  • Counting shortcut. A list of exactly dim⁡W\dim W vectors in WW is a basis as soon as it is independent, and also as soon as it spans.

With b1=(1,0)\mathbf{b}_1 = (1, 0) and b2=(1,1)\mathbf{b}_2 = (1, 1), every (x,y)(x, y) equals (x−y)b1+yb2(x - y)\mathbf{b}_1 + y\mathbf{b}_2, so (3,2)(3, 2) has coordinates (1,2)(1, 2) and (4,1)(4, 1) has coordinates (3,1)(3, 1). The plane z=x+yz = x + y has dimension 22, with basis (1,0,1)(1, 0, 1), (0,1,1)(0, 1, 1), and adding e3\mathbf{e}_3, which lies off the plane, extends it to a basis of R3\mathbb{R}^3.

Lessons Bases and Dimension

The four fundamental subspaces

Let AA be a real m×nm \times n matrix of rank rr, the number of pivots in an echelon form. Its column space Col⁡A\operatorname{Col} A is the span of the columns, which is the set of all AxA\mathbf{x}. Its row space Row⁡A=Col⁡A⊤\operatorname{Row} A = \operatorname{Col} A^{\top} is the span of the rows, read as vectors of Rn\mathbb{R}^n. Its null space Null⁡A\operatorname{Null} A is the solution set of Ax=0A\mathbf{x} = \mathbf{0}, and its left null space Null⁡A⊤\operatorname{Null} A^{\top} is the solution set of A⊤y=0A^{\top}\mathbf{y} = \mathbf{0}.

SubspaceAmbient spaceDimensionBasis by elimination
Col⁡A\operatorname{Col} ARm\mathbb{R}^mrrthe pivot columns of AA itself
Row⁡A\operatorname{Row} ARn\mathbb{R}^nrrthe nonzero rows of an echelon form
Null⁡A\operatorname{Null} ARn\mathbb{R}^nn−rn - rone solution for each free variable
Null⁡A⊤\operatorname{Null} A^{\top}Rm\mathbb{R}^mm−rm - rthe same method applied to A⊤A^{\top}

Row operations keep the row space and the null space but usually change the column space, so a basis of Col⁡A\operatorname{Col} A uses the pivot columns of the original matrix. The rank satisfies rank⁡A=dim⁡Col⁡A=dim⁡Row⁡A\operatorname{rank} A = \dim \operatorname{Col} A = \dim \operatorname{Row} A, so rank⁡A⊤=rank⁡A≤min⁡(m,n)\operatorname{rank} A^{\top} = \operatorname{rank} A \le \min(m, n). The system Ax=bA\mathbf{x} = \mathbf{b} is consistent exactly when b\mathbf{b} lies in Col⁡A\operatorname{Col} A. A matrix of rank r≥1r \ge 1 has a rank factorization A=CRA = CR, with CC the m×rm \times r matrix of pivot columns and RR the rr nonzero rows of the reduced row echelon form.

The matrix

M=[121240361]M = \begin{bmatrix} 1 & 2 & 1 \\ 2 & 4 & 0 \\ 3 & 6 & 1 \end{bmatrix}

has reduced row echelon form with nonzero rows (1,2,0)(1, 2, 0) and (0,0,1)(0, 0, 1), so its rank is 22 and columns 11 and 33 are the pivot columns.

  • The column space has basis (1,2,3)(1, 2, 3), (1,0,1)(1, 0, 1), taken from MM itself.
  • The row space has basis (1,2,0)(1, 2, 0), (0,0,1)(0, 0, 1).
  • The null space is spanned by (−2,1,0)(-2, 1, 0).
  • The left null space is spanned by (−1,−1,1)(-1, -1, 1).

Lessons Column Space, Row Space and Rank, Null Space and Left Null Space

Linear Transformations and Coordinates

This unit studies linear maps apart from any one matrix. When the input space is finite-dimensional, the dimensions of the kernel and the image add up to its dimension. A fixed vector gets new coordinates in a new basis, a fixed map gets a new matrix, and polynomials and matrices become vectors with coordinates of their own.

Kernel, image and rank-nullity

For a linear map T ⁣:V→WT \colon V \to W, the kernel ker⁡T\ker T is the set of v\mathbf{v} in VV with T(v)=0T(\mathbf{v}) = \mathbf{0}, a subspace of VV, and the image im⁡T\operatorname{im} T is the set of all outputs T(v)T(\mathbf{v}), a subspace of WW. For T(x)=AxT(\mathbf{x}) = A\mathbf{x} they are Null⁡A\operatorname{Null} A and Col⁡A\operatorname{Col} A. When VV is finite-dimensional, the rank-nullity theorem says

dim⁡ker⁡T+rank⁡T=dim⁡V,\dim \ker T + \operatorname{rank} T = \dim V,

where rank⁡T=dim⁡im⁡T\operatorname{rank} T = \dim \operatorname{im} T. For an m×nm \times n matrix this reads dim⁡Null⁡A+rank⁡A=n\dim \operatorname{Null} A + \operatorname{rank} A = n.

PropertyTestPossible only when
Injective, one-to-oneker⁡T={0}\ker T = \{\mathbf{0}\}, equivalently rank⁡T=dim⁡V\operatorname{rank} T = \dim Vdim⁡V≤dim⁡W\dim V \le \dim W
Surjective, ontoim⁡T=W\operatorname{im} T = W, equivalently rank⁡T=dim⁡W\operatorname{rank} T = \dim Wdim⁡V≥dim⁡W\dim V \ge \dim W
Bijectiveboth testsdim⁡V=dim⁡W\dim V = \dim W, and then either test implies the other

The table assumes VV and WW finite-dimensional. The fiber over b\mathbf{b}, the set of inputs with T(x)=bT(\mathbf{x}) = \mathbf{b}, is either empty or a translated kernel xp+ker⁡T\mathbf{x}_p + \ker T. For linear maps T ⁣:U→VT \colon U \to V and S ⁣:V→WS \colon V \to W, the composition satisfies ker⁡T⊆ker⁡(S∘T)\ker T \subseteq \ker(S \circ T) and rank⁡(S∘T)≤min⁡(rank⁡S,rank⁡T)\operatorname{rank}(S \circ T) \le \min(\operatorname{rank} S, \operatorname{rank} T), so a later map cannot restore a direction that an earlier one lost.

The 2×32 \times 3 matrix AA has rank 22 and nullity 11, and 2+1=32 + 1 = 3. No linear map from R4\mathbb{R}^4 to R2\mathbb{R}^2 is injective, since its rank is at most 22 and so its nullity is at least 22.

Lessons Kernel, Image and Rank-Nullity

Change of basis

Let B=(b1,…,bn)\mathcal{B} = (\mathbf{b}_1, \dots, \mathbf{b}_n) be an ordered basis of Rn\mathbb{R}^n with basis matrix B=[ b1 ⋯ bn ]B = [\,\mathbf{b}_1 \ \cdots \ \mathbf{b}_n\,], which is invertible. Then

v=B[v]B,[v]B=B−1v,\mathbf{v} = B[\mathbf{v}]_{\mathcal{B}}, \qquad [\mathbf{v}]_{\mathcal{B}} = B^{-1}\mathbf{v},

and in practice [v]B[\mathbf{v}]_{\mathcal{B}} is found by solving Bc=vB\mathbf{c} = \mathbf{v}. For a second ordered basis C\mathcal{C} with basis matrix CC, the change-of-basis matrix from B\mathcal{B} to C\mathcal{C} is

PC←B=C−1B,[v]C=PC←B[v]B.\begin{gathered} P_{\mathcal{C} \leftarrow \mathcal{B}} = C^{-1}B, \\[0.4em] [\mathbf{v}]_{\mathcal{C}} = P_{\mathcal{C} \leftarrow \mathcal{B}}[\mathbf{v}]_{\mathcal{B}}. \end{gathered}

Its column jj is [bj]C[\mathbf{b}_j]_{\mathcal{C}}, its inverse is PB←C=B−1CP_{\mathcal{B} \leftarrow \mathcal{C}} = B^{-1}C, and conversions chain as PD←CPC←B=PD←BP_{\mathcal{D} \leftarrow \mathcal{C}}P_{\mathcal{C} \leftarrow \mathcal{B}} = P_{\mathcal{D} \leftarrow \mathcal{B}}. A change of coordinates is passive. The vector stays where it is and only its description changes, while applying a matrix as a map is active and can move the vector. A coordinate list means something only together with the name of its basis.

Take B=((1,0),(1,1))\mathcal{B} = ((1, 0), (1, 1)) and C=((1,1),(1,−1))\mathcal{C} = ((1, 1), (1, -1)). Then

PC←B=C−1B=12[1210],P_{\mathcal{C} \leftarrow \mathcal{B}} = C^{-1}B = \frac{1}{2}\begin{bmatrix} 1 & 2 \\ 1 & 0 \end{bmatrix},

and the vector v=(3,2)\mathbf{v} = (3, 2), with [v]B=(1,2)[\mathbf{v}]_{\mathcal{B}} = (1, 2), has [v]C=(52,12)[\mathbf{v}]_{\mathcal{C}} = (\tfrac{5}{2}, \tfrac{1}{2}). Rebuilding gives 52(1,1)+12(1,−1)=(3,2)\tfrac{5}{2}(1, 1) + \tfrac{1}{2}(1, -1) = (3, 2).

Lessons Change of Basis for Vector Coordinates

Matrices of a linear map

For a linear map T ⁣:V→WT \colon V \to W between finite-dimensional spaces, with an ordered basis B=(v1,…,vn)\mathcal{B} = (\mathbf{v}_1, \dots, \mathbf{v}_n) of VV and an ordered basis C\mathcal{C} of WW, the matrix of TT has the output coordinates of the input basis vectors as columns,

[T]C←B=[[T(v1)]C⋯[T(vn)]C].\begin{aligned} &[T]_{\mathcal{C} \leftarrow \mathcal{B}} \\[0.4em] &\quad = \begin{bmatrix} [T(\mathbf{v}_1)]_{\mathcal{C}} & \cdots & [T(\mathbf{v}_n)]_{\mathcal{C}} \end{bmatrix}. \end{aligned}

It is the only matrix with [T(v)]C=[T]C←B[v]B[T(\mathbf{v})]_{\mathcal{C}} = [T]_{\mathcal{C} \leftarrow \mathcal{B}}[\mathbf{v}]_{\mathcal{B}} for every v\mathbf{v} in VV. For a map from Rn\mathbb{R}^n to Rm\mathbb{R}^m with standard matrix AA and basis matrices BB and CC,

[T]C←B=C−1AB.[T]_{\mathcal{C} \leftarrow \mathcal{B}} = C^{-1}AB.

A linear operator maps a space to itself and uses one basis on both sides, so [T]B=B−1AB[T]_{\mathcal{B}} = B^{-1}AB, or equivalently B[T]B=ABB[T]_{\mathcal{B}} = AB, which says that the two routes around the commutative diagram agree.

Similar matrices. Square matrices AA and A′A' are similar when A′=P−1APA' = P^{-1}AP for an invertible PP. The matrices of one operator in two bases are similar, and similar matrices share rank, determinant, trace, characteristic polynomial and eigenvalues. Passing from AA to C−1ABC^{-1}AB, with unrelated input and output bases, is more general and is not called similarity. Changing the basis can change the entries, but never the operator, its kernel or its image.

For A=diag⁡(2,1)A = \operatorname{diag}(2, 1) and the basis B=((1,0),(1,1))\mathcal{B} = ((1, 0), (1, 1)),

[T]B=B−1AB=[2101].[T]_{\mathcal{B}} = B^{-1}AB = \begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix}.

The vector (3,2)(3, 2) has B\mathcal{B}-coordinates (1,2)(1, 2), this matrix sends them to (4,2)(4, 2), and 4(1,0)+2(1,1)=(6,2)4(1, 0) + 2(1, 1) = (6, 2) is exactly AA times (3,2)(3, 2).

Lessons Matrices in Different Bases

Vector spaces beyond arrows

A real vector space is a set VV with an addition and a multiplication by real scalars that stay in VV and obey the usual laws. Addition is commutative and associative, there is a zero vector, every vector has an additive inverse, a(bu)=(ab)ua(b\mathbf{u}) = (ab)\mathbf{u} and 1u=u1\mathbf{u} = \mathbf{u}, and both distributive laws hold. Subspaces, spans, independence, bases, dimension, kernels and images carry over unchanged.

SpaceVectorsStandard ordered basisDimension
Rn\mathbb{R}^ncolumns of nn real numberse1,…,en\mathbf{e}_1, \dots, \mathbf{e}_nnn
P2P_2polynomials a0+a1t+a2t2a_0 + a_1t + a_2t^21,t,t21, t, t^233
PnP_npolynomials of degree at most nn1,t,…,tn1, t, \dots, t^nn+1n + 1
M2×2M_{2 \times 2}real 2×22 \times 2 matricesE11,E12,E21,E22E_{11}, E_{12}, E_{21}, E_{22}44
Mm×nM_{m \times n}real m×nm \times n matricesthe matrix units EijE_{ij}mnmn

Here EijE_{ij} has a 11 in row ii and column jj and zeros elsewhere. Coordinates in these bases are the coefficients or the entries, so in the basis S=(1,t,t2)\mathcal{S} = (1, t, t^2) the polynomial 2+3t−t22 + 3t - t^2 has coordinates (2,3,−1)(2, 3, -1). Polynomials of degree exactly 22 do not form a vector space, since the zero polynomial is missing and a sum can drop the degree. The degree of a polynomial, the shape of its graph and the dimension of the space it lives in are three different things.

Lessons Vector Spaces of Polynomials and Matrices

Linear maps on polynomials and matrices

A linear map on a finite-dimensional space is determined by the images of a basis, and any choice of images in the target space, repeats allowed, gives exactly one linear map. Its matrix in chosen bases is built column by column as above, and kernel, image and rank-nullity are computed through coordinates. To verify a proposed basis of a subspace HH, check that each vector lies in HH, that the list is independent and that it spans HH, or replace the last check by a dimension count when dim⁡H\dim H is known.

Evaluation. For sample points s1,…,sks_1, \dots, s_k, the map E(p)=(p(s1),…,p(sk))E(p) = (p(s_1), \dots, p(s_k)) from P2P_2 to Rk\mathbb{R}^k is linear. With E(p)=(p(0),p(1))E(p) = (p(0), p(1)), the basis (1,t,t2)(1, t, t^2) and the standard basis of R2\mathbb{R}^2, its matrix is

[100111],\begin{bmatrix} 1 & 0 & 0 \\ 1 & 1 & 1 \end{bmatrix},

so E(2+3t−t2)=(2,4)E(2 + 3t - t^2) = (2, 4), the kernel is span⁡{t2−t}\operatorname{span}\{t^2 - t\}, the image is R2\mathbb{R}^2, and 1+2=3=dim⁡P21 + 2 = 3 = \dim P_2. For any two distinct sample points s1≠s2s_1 \ne s_2 the kernel is spanned by (t−s1)(t−s2)(t - s_1)(t - s_2).

Trace. The trace tr⁡X=x11+⋯+xnn\operatorname{tr} X = x_{11} + \cdots + x_{nn} is a linear map from Mn×nM_{n \times n} to R\mathbb{R}. On M2×2M_{2 \times 2}, in the basis (E11,E12,E21,E22)(E_{11}, E_{12}, E_{21}, E_{22}), it has the 1×41 \times 4 matrix [1001]\begin{bmatrix} 1 & 0 & 0 & 1 \end{bmatrix}, rank 11 and a kernel of dimension 33 with basis E12E_{12}, E21E_{21}, E11−E22E_{11} - E_{22}.

Lessons Linear Maps on Polynomials and Matrices, Vector Spaces and Coordinates Workshop

Determinants

The determinant of a square matrix is the signed factor by which its map scales area or volume. Its sign records orientation, it is zero exactly when the columns are dependent, and the determinant of a product is the product of the determinants. Row operations compute it efficiently, and Cramer’s rule uses it to solve small square systems.

Determinants as oriented area and volume

For a real 2×22 \times 2 matrix,

det⁡[abcd]=ad−bc,\det \begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc,

the oriented area of the parallelogram spanned by the ordered columns, positive when the counterclockwise angle from the first column to the second lies strictly between 00 and π\pi. For a 3×33 \times 3 matrix it is the oriented volume of the parallelepiped spanned by the columns, positive for a right-handed triple. Only square matrices have determinants.

  • Volume scale factor. The map x↦Ax\mathbf{x} \mapsto A\mathbf{x} multiplies every area in the plane, or every volume in space, by ∣det⁡A∣\lvert \det A \rvert, and in Rn\mathbb{R}^n it scales nn-dimensional volume by the same factor.
  • Orientation. An invertible map keeps orientation when det⁡A>0\det A > 0 and reverses it when det⁡A<0\det A < 0.
  • Collapse. The determinant is 00 exactly when the columns are linearly dependent, and then the map flattens space into a subspace of lower dimension.

The matrix with columns (2,0)(2, 0) and (1,3)(1, 3) has determinant 66, so it multiplies areas by 66 and keeps orientation. Swapping its columns gives −6-6, the same area with the orientation reversed. The matrix diag⁡(2,3,−1)\operatorname{diag}(2, 3, -1) has determinant −6-6 and volume scale factor 66, and the columns (1,2)(1, 2) and (2,4)(2, 4) give determinant 00.

Lessons Determinants as Oriented Area and Volume

Computing determinants

Row operationEffect on the determinant
swap two rowsmultiplies it by −1-1
multiply one row by kkmultiplies it by kk
add a multiple of one row to a different rowno change

Since det⁡A⊤=det⁡A\det A^{\top} = \det A, the same rules hold for columns. The determinant of a triangular matrix is the product of its diagonal entries, so reducing AA to an upper triangular UU with ss swaps and some replacements, and no scalings, gives

det⁡A=(−1)s u11u22⋯unn.\det A = (-1)^s\,u_{11}u_{22} \cdots u_{nn}.

Cofactor expansion. Let the minor MijM_{ij} be the determinant of AA with row ii and column jj deleted, and the cofactor be Cij=(−1)i+jMijC_{ij} = (-1)^{i + j}M_{ij}. Expansion along any row ii or any column jj gives

det⁡A=∑k=1naikCik=∑k=1nakjCkj.\det A = \sum_{k=1}^{n} a_{ik}C_{ik} = \sum_{k=1}^{n} a_{kj}C_{kj}.

The signs follow a checkerboard that starts with ++ in the top left corner. Expansion pays off along a row or column with many zeros.

RuleCondition
det⁡(AB)=det⁡A det⁡B\det(AB) = \det A \, \det BAA and BB both n×nn \times n
det⁡(A−1)=1det⁡A\det(A^{-1}) = \dfrac{1}{\det A}AA invertible
det⁡(cA)=cndet⁡A\det(cA) = c^n \det AAA is n×nn \times n
linear in each column when the other columns are fixedin general det⁡(A+B)≠det⁡A+det⁡B\det(A + B) \ne \det A + \det B
two equal columns or rows give 00square AA

The matrix

M=[120251013]⟶[120011002]M = \begin{bmatrix} 1 & 2 & 0 \\ 2 & 5 & 1 \\ 0 & 1 & 3 \end{bmatrix} \longrightarrow \begin{bmatrix} 1 & 2 & 0 \\ 0 & 1 & 1 \\ 0 & 0 & 2 \end{bmatrix}

is reduced by R2→R2−2R1R_2 \to R_2 - 2R_1 and then R3→R3−R2R_3 \to R_3 - R_2, two replacements, so det⁡M=1⋅1⋅2=2\det M = 1 \cdot 1 \cdot 2 = 2. Expansion along the first row agrees, 1(15−1)−2(6−0)+0=21(15 - 1) - 2(6 - 0) + 0 = 2.

Lessons Computing Determinants with Row Operations

Invertibility and Cramer’s rule

For a real n×nn \times n matrix AA the following statements are equivalent.

  • The determinant det⁡A\det A is not zero.
  • The matrix AA is invertible, with nn pivots and rank nn.
  • The null space is {0}\{\mathbf{0}\}, and the columns form a basis of Rn\mathbb{R}^n.
  • Every system Ax=bA\mathbf{x} = \mathbf{b} with b\mathbf{b} in Rn\mathbb{R}^n has exactly one solution.
  • The number 00 is not an eigenvalue of AA.

When det⁡A=0\det A = 0, a square system has either no solution or infinitely many, and the determinant cannot tell which, since it does not depend on b\mathbf{b}. Row reduction of [ A∣b ][\,A \mid \mathbf{b}\,] decides. Rectangular matrices have no determinant and are studied with rank.

Cramer’s rule. Let det⁡A≠0\det A \ne 0 and let AiA_i be AA with column ii replaced by b\mathbf{b}. The unique solution of Ax=bA\mathbf{x} = \mathbf{b} is

xi=det⁡Aidet⁡A,i=1,…,n.x_i = \frac{\det A_i}{\det A}, \qquad i = 1, \dots, n.

It suits small or symbolic systems. For larger systems it costs far more than elimination or an LU factorization, and elimination also handles singular systems.

For x+y=3x + y = 3 and 2x−y=02x - y = 0 the determinants are det⁡A=−3\det A = -3, det⁡A1=−3\det A_1 = -3 and det⁡A2=−6\det A_2 = -6, so x=1x = 1 and y=2y = 2.

Lessons Determinants, Invertibility and Cramer’s Rule

Orthogonality and Projections

Inner products bring length, angle and perpendicularity into linear algebra. Projection finds the closest vector on a line or in a subspace, orthogonal complements pair up the four fundamental subspaces, and the Gram-Schmidt process turns independent vectors into orthonormal ones, recorded as a QR factorization.

Dot product, length and angle

QuantityFormulaCondition
Dot productx⋅y=x⊤y=x1y1+⋯+xnyn\mathbf{x} \cdot \mathbf{y} = \mathbf{x}^{\top}\mathbf{y} = x_1y_1 + \cdots + x_ny_nsame number of entries
Length∥x∥=x⋅x\lVert \mathbf{x} \rVert = \sqrt{\mathbf{x} \cdot \mathbf{x}}zero only for x=0\mathbf{x} = \mathbf{0}
Unit vectorx∥x∥\dfrac{\mathbf{x}}{\lVert \mathbf{x} \rVert}x≠0\mathbf{x} \ne \mathbf{0}
Distance∥x−y∥\lVert \mathbf{x} - \mathbf{y} \rVertany x\mathbf{x} and y\mathbf{y} in Rn\mathbb{R}^n
Orthogonalx⋅y=0\mathbf{x} \cdot \mathbf{y} = 00\mathbf{0} is orthogonal to every vector
Anglecos⁡θ=x⋅y∥x∥ ∥y∥\cos\theta = \dfrac{\mathbf{x} \cdot \mathbf{y}}{\lVert \mathbf{x} \rVert \, \lVert \mathbf{y} \rVert} with 0≤θ≤π0 \le \theta \le \pix\mathbf{x} and y\mathbf{y} nonzero

The rules ∥cx∥=∣c∣ ∥x∥\lVert c\mathbf{x} \rVert = \lvert c \rvert \, \lVert \mathbf{x} \rVert and

∥x−y∥2=∥x∥2+∥y∥2−2 x⋅y\begin{aligned} \lVert \mathbf{x} - \mathbf{y} \rVert^2 &= \lVert \mathbf{x} \rVert^2 + \lVert \mathbf{y} \rVert^2 \\[0.4em] &\quad - 2\,\mathbf{x} \cdot \mathbf{y} \end{aligned}

hold for all vectors, so orthogonality is the Pythagorean condition. The vectors (1,2)(1, 2) and (2,−1)(2, -1) are orthogonal and both have length 5\sqrt{5}. The distance between (1,2)(1, 2) and (4,6)(4, 6) is the length of (3,4)(3, 4), which is 55. The angle between (1,1,0)(1, 1, 0) and (1,0,1)(1, 0, 1) has cosine 122=12\frac{1}{\sqrt{2}\sqrt{2}} = \frac{1}{2}, so it is π3\frac{\pi}{3}.

Lessons Dot Products, Length and Angle

Inner products and Cauchy-Schwarz

A real inner product on a vector space VV assigns a real number ⟨u,v⟩\langle \mathbf{u}, \mathbf{v} \rangle to each pair of vectors so that, for all vectors and every real cc,

⟨u,v⟩=⟨v,u⟩,⟨u+w,v⟩=⟨u,v⟩+⟨w,v⟩,⟨cu,v⟩=c ⟨u,v⟩,⟨v,v⟩>0 whenever v≠0.\begin{aligned} &\langle \mathbf{u}, \mathbf{v} \rangle = \langle \mathbf{v}, \mathbf{u} \rangle, \\[0.4em] &\langle \mathbf{u} + \mathbf{w}, \mathbf{v} \rangle = \langle \mathbf{u}, \mathbf{v} \rangle + \langle \mathbf{w}, \mathbf{v} \rangle, \\[0.4em] &\langle c\mathbf{u}, \mathbf{v} \rangle = c\,\langle \mathbf{u}, \mathbf{v} \rangle, \\[0.4em] &\langle \mathbf{v}, \mathbf{v} \rangle > 0 \text{ whenever } \mathbf{v} \ne \mathbf{0}. \end{aligned}

These are symmetry, linearity in the first argument and positive definiteness. The norm is ∥v∥=⟨v,v⟩\lVert \mathbf{v} \rVert = \sqrt{\langle \mathbf{v}, \mathbf{v} \rangle}, and distance, orthogonality and angle are defined from the inner product as for the dot product. On Rn\mathbb{R}^n the weighted inner product ⟨x,y⟩G=x⊤Gy\langle \mathbf{x}, \mathbf{y} \rangle_G = \mathbf{x}^{\top}G\mathbf{y} with G=diag⁡(w1,…,wn)G = \operatorname{diag}(w_1, \dots, w_n) needs every weight wi>0w_i > 0. More generally x⊤Gy\mathbf{x}^{\top}G\mathbf{y} is an inner product exactly when GG is symmetric and positive definite. For all vectors in a real inner product space,

∣⟨u,v⟩∣≤∥u∥ ∥v∥,∥u+v∥≤∥u∥+∥v∥.\begin{gathered} \lvert \langle \mathbf{u}, \mathbf{v} \rangle \rvert \le \lVert \mathbf{u} \rVert \, \lVert \mathbf{v} \rVert, \\[0.4em] \lVert \mathbf{u} + \mathbf{v} \rVert \le \lVert \mathbf{u} \rVert + \lVert \mathbf{v} \rVert. \end{gathered}

The first is the Cauchy-Schwarz inequality. It is an equality exactly when u\mathbf{u} and v\mathbf{v} are linearly dependent, and it puts the cosine of every angle in [−1,1][-1, 1]. The second is the triangle inequality, an equality exactly when one vector is a nonnegative multiple of the other.

With G=diag⁡(4,1)G = \operatorname{diag}(4, 1), the vectors (1,1)(1, 1) and (1,−1)(1, -1), which are perpendicular for the dot product, have inner product 4−1=34 - 1 = 3 and norms 5\sqrt{5}, so their angle has cosine 35\frac{3}{5}. Length and angle depend on the inner product chosen. The weights 11 and −1-1 do not give an inner product, since (0,1)(0, 1) would have ⟨v,v⟩=−1\langle \mathbf{v}, \mathbf{v} \rangle = -1.

Lessons Inner Products and Cauchy-Schwarz

Orthonormal bases and projection onto a line

A list is orthogonal when its vectors are pairwise orthogonal, and orthonormal when in addition each vector has norm 11. An orthogonal list of nonzero vectors is linearly independent. In an orthonormal basis (q1,…,qn)(\mathbf{q}_1, \dots, \mathbf{q}_n) the coordinates are inner products,

v=⟨q1,v⟩q1+⋯+⟨qn,v⟩qn.\begin{aligned} \mathbf{v} &= \langle \mathbf{q}_1, \mathbf{v} \rangle \mathbf{q}_1 + \cdots \\[0.4em] &\quad + \langle \mathbf{q}_n, \mathbf{v} \rangle \mathbf{q}_n. \end{aligned}

Projection onto a line. For u≠0\mathbf{u} \ne \mathbf{0} and the line L=span⁡{u}L = \operatorname{span}\{\mathbf{u}\},

proj⁡Lb=u⋅bu⋅u u.\operatorname{proj}_L \mathbf{b} = \frac{\mathbf{u} \cdot \mathbf{b}}{\mathbf{u} \cdot \mathbf{u}}\,\mathbf{u}.

The scalar in front is the projection coefficient. It changes when u\mathbf{u} is rescaled, while the projected vector depends only on the line. The residual r=b−proj⁡Lb\mathbf{r} = \mathbf{b} - \operatorname{proj}_L \mathbf{b} is orthogonal to u\mathbf{u}, the lengths satisfy ∥b∥2=∥proj⁡Lb∥2+∥r∥2\lVert \mathbf{b} \rVert^2 = \lVert \operatorname{proj}_L \mathbf{b} \rVert^2 + \lVert \mathbf{r} \rVert^2, and the projection is the unique point of LL closest to b\mathbf{b}, at distance ∥r∥\lVert \mathbf{r} \rVert.

Orthogonal matrix. A real n×nn \times n matrix QQ is orthogonal when its columns form an orthonormal basis of Rn\mathbb{R}^n, that is, when Q⊤Q=IQ^{\top}Q = I. Then Q−1=Q⊤Q^{-1} = Q^{\top}, also QQ⊤=IQQ^{\top} = I, and QQ preserves dot products and lengths. An m×nm \times n matrix with orthonormal columns and m>nm > n still has Q⊤Q=InQ^{\top}Q = I_n, but QQ⊤≠ImQQ^{\top} \ne I_m.

Projecting b=(3,1)\mathbf{b} = (3, 1) onto the line through u=(1,2)\mathbf{u} = (1, 2) gives the coefficient 55=1\frac{5}{5} = 1, the projection (1,2)(1, 2) and the residual (2,−1)(2, -1), which is orthogonal to u\mathbf{u}. In the orthonormal basis 12(1,1)\frac{1}{\sqrt{2}}(1, 1), 12(1,−1)\frac{1}{\sqrt{2}}(1, -1) the same b\mathbf{b} has coordinates (22,2)(2\sqrt{2}, \sqrt{2}).

Lessons Orthonormal Coordinates and Line Projection

Orthogonal complements

For a subspace WW of Rn\mathbb{R}^n, the orthogonal complement W⊥W^{\perp} is the set of vectors of Rn\mathbb{R}^n orthogonal to every vector of WW, and it is enough to test a spanning list of WW. Then W∩W⊥={0}W \cap W^{\perp} = \{\mathbf{0}\},

dim⁡W+dim⁡W⊥=n,(W⊥)⊥=W,\begin{gathered} \dim W + \dim W^{\perp} = n, \\[0.4em] (W^{\perp})^{\perp} = W, \end{gathered}

and every vector of Rn\mathbb{R}^n splits in exactly one way as w+z\mathbf{w} + \mathbf{z} with w\mathbf{w} in WW and z\mathbf{z} in W⊥W^{\perp}, written Rn=W⊕W⊥\mathbb{R}^n = W \oplus W^{\perp}. For a real m×nm \times n matrix AA, each entry of AxA\mathbf{x} is a row of AA dotted with x\mathbf{x}, which gives

Null⁡A=(Row⁡A)⊥ in Rn,Null⁡A⊤=(Col⁡A)⊥ in Rm.\begin{aligned} \operatorname{Null} A &= (\operatorname{Row} A)^{\perp} \text{ in } \mathbb{R}^n, \\[0.4em] \operatorname{Null} A^{\top} &= (\operatorname{Col} A)^{\perp} \text{ in } \mathbb{R}^m. \end{aligned}

So Rn=Row⁡A⊕Null⁡A\mathbb{R}^n = \operatorname{Row} A \oplus \operatorname{Null} A and Rm=Col⁡A⊕Null⁡A⊤\mathbb{R}^m = \operatorname{Col} A \oplus \operatorname{Null} A^{\top}, and Ax=bA\mathbf{x} = \mathbf{b} has a solution exactly when b\mathbf{b} is orthogonal to every vector of Null⁡A⊤\operatorname{Null} A^{\top}. Orthogonality is taken inside one space, never between an input in Rn\mathbb{R}^n and an output in Rm\mathbb{R}^m.

The columns (1,0,1)(1, 0, 1) and (0,1,1)(0, 1, 1) of A⊤A^{\top} span the plane z=x+yz = x + y, whose orthogonal complement is the line through n=(−1,−1,1)\mathbf{n} = (-1, -1, 1). The vector (1,−1,0)(1, -1, 0) is orthogonal to the sum (1,1,2)(1, 1, 2) of the two columns but to neither column, so it is not in that complement.

Lessons Orthogonal Complements and the Four Subspaces

Projection onto a subspace

The orthogonal projection of b\mathbf{b} in Rm\mathbb{R}^m onto a subspace WW of Rm\mathbb{R}^m is the unique p\mathbf{p} in WW with b−p\mathbf{b} - \mathbf{p} in W⊥W^{\perp}. It is the closest vector of WW to b\mathbf{b}, since ∥b−y∥2=∥b−p∥2+∥p−y∥2\lVert \mathbf{b} - \mathbf{y} \rVert^2 = \lVert \mathbf{b} - \mathbf{p} \rVert^2 + \lVert \mathbf{p} - \mathbf{y} \rVert^2 for every y\mathbf{y} in WW. If the columns of an m×km \times k matrix CC form a basis of WW, then p=Cx^\mathbf{p} = C\hat{\mathbf{x}}, where x^\hat{\mathbf{x}} solves the normal equations, and p=Pb\mathbf{p} = P\mathbf{b} with the projection matrix PP,

C⊤C x^=C⊤b,P=C(C⊤C)−1C⊤.\begin{gathered} C^{\top}C\,\hat{\mathbf{x}} = C^{\top}\mathbf{b}, \\[0.4em] P = C(C^{\top}C)^{-1}C^{\top}. \end{gathered}

The k×kk \times k matrix C⊤CC^{\top}C is invertible because the columns are independent.

Description of WWProjectionCondition
orthonormal columns of QQP=QQ⊤P = QQ^{\top}, so p=∑i(qi⋅b) qi\mathbf{p} = \sum_i (\mathbf{q}_i \cdot \mathbf{b})\,\mathbf{q}_iQ⊤Q=IQ^{\top}Q = I
orthogonal basis w1,…,wk\mathbf{w}_1, \dots, \mathbf{w}_kp=∑iwi⋅bwi⋅wi wi\mathbf{p} = \sum_i \dfrac{\mathbf{w}_i \cdot \mathbf{b}}{\mathbf{w}_i \cdot \mathbf{w}_i}\,\mathbf{w}_inonzero and pairwise orthogonal
any basis, the columns of CCP=C(C⊤C)−1C⊤P = C(C^{\top}C)^{-1}C^{\top}independent columns
plane n⋅x=0\mathbf{n} \cdot \mathbf{x} = 0p=b−b⋅nn⋅n n\mathbf{p} = \mathbf{b} - \dfrac{\mathbf{b} \cdot \mathbf{n}}{\mathbf{n} \cdot \mathbf{n}}\,\mathbf{n}n≠0\mathbf{n} \ne \mathbf{0}

Every orthogonal projection matrix satisfies P2=PP^2 = P and P⊤=PP^{\top} = P, and conversely a real square matrix with both properties is the orthogonal projection onto its column space. The projection depends only on WW, not on the basis. For a basis that is not orthogonal, adding the line projections onto the basis vectors does not give the projection in general.

For CC with columns (1,0,1)(1, 0, 1) and (0,1,1)(0, 1, 1) and b=(1,1,0)\mathbf{b} = (1, 1, 0), the normal equations read

[2112]x^=[11],\begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix}\hat{\mathbf{x}} = \begin{bmatrix} 1 \\ 1 \end{bmatrix},

so x^=(13,13)\hat{\mathbf{x}} = (\tfrac{1}{3}, \tfrac{1}{3}), the projection is p=(13,13,23)\mathbf{p} = (\tfrac{1}{3}, \tfrac{1}{3}, \tfrac{2}{3}), and the residual (23,23,−23)(\tfrac{2}{3}, \tfrac{2}{3}, -\tfrac{2}{3}) is orthogonal to both columns.

Lessons Projection onto a Subspace

Gram-Schmidt and QR

For linearly independent a1,…,an\mathbf{a}_1, \dots, \mathbf{a}_n in Rm\mathbb{R}^m, the Gram-Schmidt process sets, for j=1,…,nj = 1, \dots, n in turn,

uj=aj−∑i=1j−1(qi⋅aj) qi,qj=uj∥uj∥.\begin{aligned} \mathbf{u}_j &= \mathbf{a}_j - \sum_{i=1}^{j-1} (\mathbf{q}_i \cdot \mathbf{a}_j)\,\mathbf{q}_i, \\[0.4em] \mathbf{q}_j &= \frac{\mathbf{u}_j}{\lVert \mathbf{u}_j \rVert}. \end{aligned}

Each remainder uj\mathbf{u}_j is nonzero and orthogonal to the earlier qi\mathbf{q}_i, the vectors qj\mathbf{q}_j are orthonormal, and for every jj the first jj of them span the same subspace as a1,…,aj\mathbf{a}_1, \dots, \mathbf{a}_j. For a dependent list, a zero remainder appears exactly when aj\mathbf{a}_j is a combination of the earlier vectors, and it cannot be normalized. Normalizing changes lengths only, so it never makes vectors orthogonal by itself.

Reduced QR factorization. An m×nm \times n matrix AA with independent columns factors as A=QRA = QR, where the m×nm \times n matrix QQ has the orthonormal columns qj\mathbf{q}_j and R=Q⊤AR = Q^{\top}A is n×nn \times n upper triangular, with rij=qi⋅ajr_{ij} = \mathbf{q}_i \cdot \mathbf{a}_j for i<ji < j and rjj=∥uj∥>0r_{jj} = \lVert \mathbf{u}_j \rVert > 0. With a positive diagonal the factors are unique. In floating-point arithmetic this direct form of the process can lose orthogonality, so a tiny computed remainder needs care.

For a1=(1,0,1)\mathbf{a}_1 = (1, 0, 1) and a2=(0,1,1)\mathbf{a}_2 = (0, 1, 1), the first step gives q1=12(1,0,1)\mathbf{q}_1 = \frac{1}{\sqrt{2}}(1, 0, 1). Then q1⋅a2=12\mathbf{q}_1 \cdot \mathbf{a}_2 = \frac{1}{\sqrt{2}}, the remainder is u2=(−12,1,12)\mathbf{u}_2 = (-\tfrac{1}{2}, 1, \tfrac{1}{2}) with length 62\frac{\sqrt{6}}{2}, and q2=16(−1,2,1)\mathbf{q}_2 = \frac{1}{\sqrt{6}}(-1, 2, 1), so

R=[212062].R = \begin{bmatrix} \sqrt{2} & \tfrac{1}{\sqrt{2}} \\ 0 & \tfrac{\sqrt{6}}{2} \end{bmatrix}.

Lessons Gram-Schmidt and QR Factorization

Least Squares

When a system has no exact solution, least squares picks the inputs whose output comes closest to the data. The closest output is the projection of the data onto the column space, found with the normal equations or with QR. Fitted values are always unique while coefficients may not be, and conditioning measures how far small changes in the data can move a solution.

Least-squares solutions and the normal equations

For a real m×nm \times n matrix AA and b\mathbf{b} in Rm\mathbb{R}^m, a least-squares solution x^\hat{\mathbf{x}} minimizes ∥b−Ax∥2\lVert \mathbf{b} - A\mathbf{x} \rVert^2 over all x\mathbf{x} in Rn\mathbb{R}^n. Least-squares solutions always exist, and they are exactly the solutions of the normal equations

A⊤A x^=A⊤b,A^{\top}A\,\hat{\mathbf{x}} = A^{\top}\mathbf{b},

which say that the residual r=b−Ax^\mathbf{r} = \mathbf{b} - A\hat{\mathbf{x}} is orthogonal to every column, A⊤r=0A^{\top}\mathbf{r} = \mathbf{0}.

ObjectUniqueDescription
fitted vector Ax^A\hat{\mathbf{x}}alwaysthe projection of b\mathbf{b} onto Col⁡A\operatorname{Col} A
residual r\mathbf{r}alwaysthe component of b\mathbf{b} in (Col⁡A)⊥(\operatorname{Col} A)^{\perp}
coefficients x^\hat{\mathbf{x}}exactly when rank⁡A=n\operatorname{rank} A = nthen x^=(A⊤A)−1A⊤b\hat{\mathbf{x}} = (A^{\top}A)^{-1}A^{\top}\mathbf{b}

When the columns are dependent, the least-squares solutions are x^+h\hat{\mathbf{x}} + \mathbf{h} with h\mathbf{h} in Null⁡A\operatorname{Null} A, and all give the same fitted vector. When b\mathbf{b} lies in Col⁡A\operatorname{Col} A, they are the ordinary solutions. If A⊤r=0A^{\top}\mathbf{r} = \mathbf{0}, then every x\mathbf{x} satisfies

∥b−Ax∥2=∥r∥2+∥A(x^−x)∥2,\begin{aligned} \lVert \mathbf{b} - A\mathbf{x} \rVert^2 &= \lVert \mathbf{r} \rVert^2 \\[0.4em] &\quad + \lVert A(\hat{\mathbf{x}} - \mathbf{x}) \rVert^2, \end{aligned}

so the check A⊤r=0A^{\top}\mathbf{r} = \mathbf{0} certifies a minimum.

Lessons Least Squares and Orthogonal Projection

Fitting a model

A model f(t)=c1φ1(t)+⋯+cnφn(t)f(t) = c_1\varphi_1(t) + \cdots + c_n\varphi_n(t) with known functions φj\varphi_j is linear in its coefficients, even when the φj\varphi_j are not linear in tt, so fitting it is a linear algebra problem. For data points (t1,y1),…,(tm,ym)(t_1, y_1), \dots, (t_m, y_m) it uses the m×nm \times n design matrix XX with entries Xij=φj(ti)X_{ij} = \varphi_j(t_i) and the observation vector y=(y1,…,ym)\mathbf{y} = (y_1, \dots, y_m), and least squares minimizes the sum of squared vertical residuals

∑i=1m(yi−(Xc)i)2=∥y−Xc∥2.\sum_{i=1}^{m} \bigl(y_i - (X\mathbf{c})_i\bigr)^2 = \lVert \mathbf{y} - X\mathbf{c} \rVert^2.

For a line y=a+bty = a + bt row ii of XX is [1ti]\begin{bmatrix} 1 & t_i \end{bmatrix}, and the line is unique as soon as two of the tit_i differ. When XX has a column of ones, the least-squares residuals add up to 00. The residuals are vertical in the scatter plot, and the right angle appears in observation space Rm\mathbb{R}^m, between the residual vector and Col⁡X\operatorname{Col} X. A model such as c1ec2tc_1e^{c_2t} is not linear in c2c_2, and proportional design columns leave the fitted values unique but the coefficients not.

For the points (0,1)(0, 1), (1,2)(1, 2), (2,2)(2, 2),

X⊤X=[3335],X⊤y=[56],\begin{gathered} X^{\top}X = \begin{bmatrix} 3 & 3 \\ 3 & 5 \end{bmatrix}, \\[0.4em] X^{\top}\mathbf{y} = \begin{bmatrix} 5 \\ 6 \end{bmatrix}, \end{gathered}

so a=76a = \frac{7}{6} and b=12b = \frac{1}{2}. The fitted values are (76,53,136)(\tfrac{7}{6}, \tfrac{5}{3}, \tfrac{13}{6}), the residuals (−16,13,−16)(-\tfrac{1}{6}, \tfrac{1}{3}, -\tfrac{1}{6}) add up to 00, and the smallest sum of squared errors is 16\frac{1}{6}. The best constant fit to the same outputs is their mean 53\frac{5}{3}, with squared error 23\frac{2}{3}.

Lessons Least-Squares Models and Normal Equations

Least squares with QR

Let XX be an m×nm \times n matrix with independent columns and reduced QR factorization X=QRX = QR. The unique least-squares solution solves the triangular system

Rc^=Q⊤yR\hat{\mathbf{c}} = Q^{\top}\mathbf{y}

by back-substitution, without forming X⊤XX^{\top}X. The entries of Q⊤yQ^{\top}\mathbf{y} are the coordinates of the fitted vector QQ⊤yQQ^{\top}\mathbf{y} in the orthonormal basis of Col⁡X\operatorname{Col} X, not the model coefficients. For every c\mathbf{c} in Rn\mathbb{R}^n,

∥Xc−y∥2=∥Rc−Q⊤y∥2+∥(I−QQ⊤)y∥2,\begin{aligned} \lVert X\mathbf{c} - \mathbf{y} \rVert^2 &= \lVert R\mathbf{c} - Q^{\top}\mathbf{y} \rVert^2 \\[0.4em] &\quad + \lVert (I - QQ^{\top})\mathbf{y} \rVert^2, \end{aligned}

so the smallest squared error is ∥(I−QQ⊤)y∥2=∥y∥2−∥Q⊤y∥2\lVert (I - QQ^{\top})\mathbf{y} \rVert^2 = \lVert \mathbf{y} \rVert^2 - \lVert Q^{\top}\mathbf{y} \rVert^2, the squared length of the part of y\mathbf{y} outside the model space. The triangular equation finds the best coefficients and does not claim that Xc=yX\mathbf{c} = \mathbf{y} holds exactly.

For the line fit above,

Q=[13−121301312],R=[3302],\begin{gathered} Q = \begin{bmatrix} \tfrac{1}{\sqrt{3}} & -\tfrac{1}{\sqrt{2}} \\ \tfrac{1}{\sqrt{3}} & 0 \\ \tfrac{1}{\sqrt{3}} & \tfrac{1}{\sqrt{2}} \end{bmatrix}, \\[0.4em] R = \begin{bmatrix} \sqrt{3} & \sqrt{3} \\ 0 & \sqrt{2} \end{bmatrix}, \end{gathered}

and Q⊤y=(53,12)Q^{\top}\mathbf{y} = (\tfrac{5}{\sqrt{3}}, \tfrac{1}{\sqrt{2}}). Back-substitution gives b=12b = \frac{1}{2} and then a=76a = \frac{7}{6} again, and 9−253−12=169 - \frac{25}{3} - \frac{1}{2} = \frac{1}{6} is the same squared error.

Lessons Least Squares with QR

Conditioning and sensitivity

The induced norm ∥A∥2=max⁡∥u∥=1∥Au∥\lVert A \rVert_2 = \max_{\lVert \mathbf{u} \rVert = 1} \lVert A\mathbf{u} \rVert is the largest stretch of AA, and ∥Av∥≤∥A∥2 ∥v∥\lVert A\mathbf{v} \rVert \le \lVert A \rVert_2 \, \lVert \mathbf{v} \rVert for every v\mathbf{v}. For an invertible n×nn \times n matrix with largest and smallest singular values σ1\sigma_1 and σn\sigma_n, the condition number is

κ2(A)=∥A∥2 ∥A−1∥2=σ1σn≥1,\begin{aligned} \kappa_2(A) &= \lVert A \rVert_2 \, \lVert A^{-1} \rVert_2 \\[0.4em] &= \frac{\sigma_1}{\sigma_n} \ge 1, \end{aligned}

the ratio of the largest to the smallest stretch, with κ2(cA)=κ2(A)\kappa_2(cA) = \kappa_2(A) for c≠0c \ne 0. If Ax=bA\mathbf{x} = \mathbf{b} with b≠0\mathbf{b} \ne \mathbf{0} and the data change to b+δb\mathbf{b} + \delta\mathbf{b} with AA fixed, the solution changes by δx=A−1δb\delta\mathbf{x} = A^{-1}\delta\mathbf{b} and

∥δx∥∥x∥≤κ2(A) ∥δb∥∥b∥.\frac{\lVert \delta\mathbf{x} \rVert}{\lVert \mathbf{x} \rVert} \le \kappa_2(A)\,\frac{\lVert \delta\mathbf{b} \rVert}{\lVert \mathbf{b} \rVert}.

When b=0\mathbf{b} = \mathbf{0}, use the absolute bound ∥δx∥≤∥A−1∥2 ∥δb∥\lVert \delta\mathbf{x} \rVert \le \lVert A^{-1} \rVert_2 \, \lVert \delta\mathbf{b} \rVert instead. The same bounds relate the error x−x^\mathbf{x} - \hat{\mathbf{x}} of an approximate solution to its residual b−Ax^\mathbf{b} - A\hat{\mathbf{x}}, so a small relative residual guarantees a small relative error only when κ2(A)\kappa_2(A) is moderate.

  • Ill-conditioned means that κ2(A)\kappa_2(A) is large, so that some small relative changes in the data cause much larger relative changes in the solution. There is no fixed cutoff, since whether κ2(A)\kappa_2(A) counts as large depends on how accurate the data are. A small determinant is not the test, since 0.001I0.001I has a tiny determinant and condition number 11.
  • Conditioning versus stability. Conditioning belongs to the problem and stability to the algorithm. Pivoting and guard digits help an algorithm, but nothing lowers the condition number of the problem itself.
  • Normal equations. For XX of full column rank, forming X⊤XX^{\top}X squares the ratio σ1/σn\sigma_1 / \sigma_n, while QR keeps it, so QR is the safer route in floating point.

The system

[1111.01]x=[22.01]\begin{bmatrix} 1 & 1 \\ 1 & 1.01 \end{bmatrix}\mathbf{x} = \begin{bmatrix} 2 \\ 2.01 \end{bmatrix}

has the solution (1,1)(1, 1). Changing 2.012.01 to 2.022.02, a relative change of about 0.350.35 percent in b\mathbf{b}, moves the solution to (0,2)(0, 2), a relative change of 100100 percent. Here κ2(A)≈402\kappa_2(A) \approx 402.

Lessons Conditioning and Sensitivity

Choosing the question

Fix the error criterion before calculating, because each criterion asks a different question and needs its own check.

QuestionCriterionSolve and check
exact solveAx=bA\mathbf{x} = \mathbf{b}, possible when b\mathbf{b} lies in Col⁡A\operatorname{Col} Aelimination, then a residual of exactly 0\mathbf{0}
projection onto WWminimize ∥b−p∥\lVert \mathbf{b} - \mathbf{p} \rVert over p\mathbf{p} in WWnormal equations, then p\mathbf{p} in WW and b−p\mathbf{b} - \mathbf{p} in W⊥W^{\perp}
least-squares fitminimize ∥y−Xc∥2\lVert \mathbf{y} - X\mathbf{c} \rVert^2normal equations or QR, then X⊤r=0X^{\top}\mathbf{r} = \mathbf{0} and the rank of XX
weighted fitminimize ∑iwiri2\sum_i w_ir_i^2 with every wi>0w_i > 0scale row ii of XX and yiy_i by wi\sqrt{w_i}, then ordinary least squares

Membership and orthogonality are needed together, since every point of WW passes the first test and every point of b+W⊥\mathbf{b} + W^{\perp} passes the second. Projecting (1,0,0)(1, 0, 0) onto the plane x+y+z=0x + y + z = 0 removes 13(1,1,1)\frac{1}{3}(1, 1, 1) and leaves (23,−13,−13)(\tfrac{2}{3}, -\tfrac{1}{3}, -\tfrac{1}{3}), which passes both.

Lessons Projection and Least Squares Workshop

Eigenvalues and Diagonalization

An eigenvector of a square matrix is a nonzero vector that the matrix sends to a multiple of itself. The characteristic polynomial gives the eigenvalues and elimination gives the eigenspaces. A matrix can be diagonalized exactly when it has enough independent eigenvectors for a basis, and complex numbers supply the eigenvalues that real matrices such as rotations lack.

Eigenvalues and eigenvectors

Let AA be a real n×nn \times n matrix. A nonzero vector v\mathbf{v} is an eigenvector with eigenvalue λ\lambda when

Av=λv.A\mathbf{v} = \lambda\mathbf{v}.

The eigenspace Eλ=Null⁡(A−λI)E_\lambda = \operatorname{Null}(A - \lambda I) holds 0\mathbf{0} and all eigenvectors for λ\lambda, and every nonzero multiple of an eigenvector is again one. The line through an eigenvector is invariant. Along it the map keeps the direction when λ>0\lambda > 0, reverses it when λ<0\lambda < 0, and collapses the line to 0\mathbf{0} when λ=0\lambda = 0, with length factor ∣λ∣\lvert \lambda \rvert.

  • The number 00 is an eigenvalue exactly when AA is singular. The zero vector is never an eigenvector.
  • Eigenvectors for distinct eigenvalues are linearly independent, so AA has at most nn distinct eigenvalues.
  • If Av=λvA\mathbf{v} = \lambda\mathbf{v}, then Akv=λkvA^k\mathbf{v} = \lambda^k\mathbf{v} for every integer k≥0k \ge 0, and A−1v=λ−1vA^{-1}\mathbf{v} = \lambda^{-1}\mathbf{v} when AA is invertible.

For

S=[2112],S = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix},

the vector (1,1)(1, 1) goes to (3,3)(3, 3), so it is an eigenvector with eigenvalue 33, and (1,−1)(1, -1) is fixed, with eigenvalue 11. The vector e1\mathbf{e}_1 goes to (2,1)(2, 1), which is not a multiple of e1\mathbf{e}_1.

Lessons Eigenvectors and Eigenvalues

Characteristic polynomial and eigenspaces

The characteristic polynomial χA(t)=det⁡(tI−A)\chi_A(t) = \det(tI - A) of an n×nn \times n matrix has degree nn and leading coefficient 11. Its real roots are exactly the real eigenvalues of AA, and once complex scalars are allowed every root is an eigenvalue. For a 2×22 \times 2 matrix,

χA(t)=t2−(tr⁡A) t+det⁡A.\chi_A(t) = t^2 - (\operatorname{tr} A)\,t + \det A.

To find the eigenspace of a root λ\lambda, row reduce A−λIA - \lambda I and write the general solution of (A−λI)v=0(A - \lambda I)\mathbf{v} = \mathbf{0} with one basis vector for each free variable. A root only guarantees that some nonzero solution exists, and an eigenspace of dimension 22 or more needs a full basis, not one eigenvector.

FactCondition
the eigenvalues are the diagonal entriesAA triangular
the eigenvalues add up to tr⁡A\operatorname{tr} A and multiply to det⁡A\det Acounted with algebraic multiplicity, complex ones included
AA and P−1APP^{-1}AP have the same characteristic polynomial and eigenvaluesPP invertible

The matrix

M=[4123]M = \begin{bmatrix} 4 & 1 \\ 2 & 3 \end{bmatrix}

has χM(t)=t2−7t+10=(t−5)(t−2)\chi_M(t) = t^2 - 7t + 10 = (t - 5)(t - 2). Solving (M−5I)v=0(M - 5I)\mathbf{v} = \mathbf{0} gives E5=span⁡{(1,1)}E_5 = \operatorname{span}\{(1, 1)\}, and solving (M−2I)v=0(M - 2I)\mathbf{v} = \mathbf{0} gives E2=span⁡{(−1,2)}E_2 = \operatorname{span}\{(-1, 2)\}. The checks 5+2=7=tr⁡M5 + 2 = 7 = \operatorname{tr} M and 5⋅2=10=det⁡M5 \cdot 2 = 10 = \det M pass.

Lessons Calculating Eigenvalues and Eigenspaces

Algebraic and geometric multiplicity

For an eigenvalue λ\lambda of an n×nn \times n matrix AA, the algebraic multiplicity am⁡(λ)\operatorname{am}(\lambda) is the number of times the factor t−λt - \lambda occurs in χA\chi_A, and the geometric multiplicity is

gm⁡(λ)=dim⁡Eλ=n−rank⁡(A−λI).\begin{aligned} \operatorname{gm}(\lambda) &= \dim E_\lambda \\[0.4em] &= n - \operatorname{rank}(A - \lambda I). \end{aligned}

Always 1≤gm⁡(λ)≤am⁡(λ)1 \le \operatorname{gm}(\lambda) \le \operatorname{am}(\lambda). A matrix with gm⁡(λ)<am⁡(λ)\operatorname{gm}(\lambda) < \operatorname{am}(\lambda) for some eigenvalue is defective, and it has fewer than nn independent eigenvectors. Only a repeated eigenvalue can be deficient, since a simple root has both multiplicities equal to 11. In the table, JJ is the matrix with rows (2,1)(2, 1) and (0,2)(0, 2).

MatrixχA(t)\chi_A(t)Eigenvalue 22Defective
diag⁡(2,2,3)\operatorname{diag}(2, 2, 3)(t−2)2(t−3)(t - 2)^2(t - 3)am 22, gm 22, E2=span⁡{e1,e2}E_2 = \operatorname{span}\{\mathbf{e}_1, \mathbf{e}_2\}no
JJ(t−2)2(t - 2)^2am 22, gm 11, E2=span⁡{e1}E_2 = \operatorname{span}\{\mathbf{e}_1\}yes
2I2I in R2\mathbb{R}^2(t−2)2(t - 2)^2am 22, gm 22, E2=R2E_2 = \mathbb{R}^2no

A repeated root counts roots, not independent eigenvectors, so the eigenspace has to be computed.

Lessons Algebraic and Geometric Multiplicity

Diagonalization and matrix powers

A real n×nn \times n matrix AA is diagonalizable over R\mathbb{R} when A=PDP−1A = PDP^{-1} with PP invertible and DD diagonal, both real. This happens exactly when the columns of PP are nn independent eigenvectors, an eigenbasis, and the diagonal entries of DD are their eigenvalues in the same order. Then D=P−1APD = P^{-1}AP is the matrix of the map in the eigenbasis.

  • Test. The matrix is diagonalizable over R\mathbb{R} exactly when its real eigenspaces have dimensions adding up to nn.
  • Sufficient condition. Having nn distinct real eigenvalues is enough, but not necessary, as diag⁡(2,2,3)\operatorname{diag}(2, 2, 3) shows.
  • Failures. A defective matrix is not diagonalizable over R\mathbb{R} or over C\mathbb{C}, and a real matrix whose characteristic polynomial has a nonreal root is not diagonalizable over R\mathbb{R}.

Powers. If A=PDP−1A = PDP^{-1}, where PP has the eigenvectors v1,…,vn\mathbf{v}_1, \dots, \mathbf{v}_n as columns and D=diag⁡(λ1,…,λn)D = \operatorname{diag}(\lambda_1, \dots, \lambda_n), then for every integer k≥0k \ge 0

Ak=PDkP−1,Dk=diag⁡(λ1k,…,λnk).\begin{gathered} A^k = PD^kP^{-1}, \\[0.4em] D^k = \operatorname{diag}(\lambda_1^k, \dots, \lambda_n^k). \end{gathered}

For a repeated update xk+1=Axk\mathbf{x}_{k+1} = A\mathbf{x}_k that starts at x0=c1v1+⋯+cnvn\mathbf{x}_0 = c_1\mathbf{v}_1 + \cdots + c_n\mathbf{v}_n, where (c1,…,cn)=P−1x0(c_1, \dots, c_n) = P^{-1}\mathbf{x}_0,

xk=c1λ1kv1+⋯+cnλnkvn,\mathbf{x}_k = c_1\lambda_1^k\mathbf{v}_1 + \cdots + c_n\lambda_n^k\mathbf{v}_n,

so a component with ci≠0c_i \ne 0 grows when ∣λi∣>1\lvert \lambda_i \rvert > 1, dies out when ∣λi∣<1\lvert \lambda_i \rvert < 1, and alternates in sign when λi<0\lambda_i < 0.

For the matrix SS above, P=[111−1]P = \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} and D=diag⁡(3,1)D = \operatorname{diag}(3, 1) give

Ske1=12[3k+13k−1],S^k\mathbf{e}_1 = \frac{1}{2}\begin{bmatrix} 3^k + 1 \\ 3^k - 1 \end{bmatrix},

which is (5,4)(5, 4) for k=2k = 2. The defective matrix JJ has no eigenbasis, so this method does not apply to it, and direct multiplication gives J2=[4404]J^2 = \begin{bmatrix} 4 & 4 \\ 0 & 4 \end{bmatrix}.

Lessons Diagonalization and Matrix Powers

Complex numbers

A complex number is z=a+biz = a + bi with real aa and bb and i2=−1i^2 = -1. In the complex plane it is the point (a,b)(a, b), and addition is addition of points.

OperationFormulaCondition
Product(a+bi)(c+di)=(ac−bd)+(ad+bc)i(a + bi)(c + di) = (ac - bd) + (ad + bc)iany a,b,c,da, b, c, d
Conjugatea+bi‾=a−bi\overline{a + bi} = a - bi, with zw‾=z‾ w‾\overline{zw} = \overline{z}\,\overline{w}any zz and ww
Modulus∣z∣=a2+b2=zz‾\lvert z \rvert = \sqrt{a^2 + b^2} = \sqrt{z\overline{z}}, with ∣zw∣=∣z∣ ∣w∣\lvert zw \rvert = \lvert z \rvert \, \lvert w \rvertany zz and ww
Reciprocal1c+di=c−dic2+d2\dfrac{1}{c + di} = \dfrac{c - di}{c^2 + d^2}c+di≠0c + di \ne 0
Quotientzw=zw‾∣w∣2\dfrac{z}{w} = \dfrac{z\overline{w}}{\lvert w \rvert^2}w≠0w \ne 0

Multiplying by ii sends (a,b)(a, b) to (−b,a)(-b, a), the counterclockwise quarter-turn of the plane, with matrix [0−110]\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}. For example i(2+i)=−1+2ii(2 + i) = -1 + 2i, and

1+i1−i=(1+i)2(1−i)(1+i)=2i2=i.\frac{1 + i}{1 - i} = \frac{(1 + i)^2}{(1 - i)(1 + i)} = \frac{2i}{2} = i.

Lessons Complex Numbers for Linear Algebra

Complex eigenvalues

Over C\mathbb{C} every n×nn \times n matrix has nn eigenvalues counted with algebraic multiplicity, because χA\chi_A factors into linear factors, and their sum and product are tr⁡A\operatorname{tr} A and det⁡A\det A. Complex eigenvectors live in Cn\mathbb{C}^n, the space of columns of nn complex numbers, and for a real matrix the eigenvectors of a nonreal eigenvalue are not arrows in Rn\mathbb{R}^n. A real matrix is diagonalizable over C\mathbb{C} when Cn\mathbb{C}^n has a basis of its eigenvectors, so a claim of diagonalizability should name the scalars.

  • Conjugate pairs. If AA is real and Av=λvA\mathbf{v} = \lambda\mathbf{v}, then Av‾=λ‾ v‾A\overline{\mathbf{v}} = \overline{\lambda}\,\overline{\mathbf{v}}. The nonreal eigenvalues of a real matrix come in conjugate pairs, so a real matrix of odd size has a real eigenvalue.
  • Rotation and scaling. For real aa and b≠0b \ne 0, the matrix [a−bba]\begin{bmatrix} a & -b \\ b & a \end{bmatrix} has no real eigenvalue, and it has the eigenvalues a+bia + bi and a−bia - bi with eigenvectors (1,−i)(1, -i) and (1,i)(1, i) in that order. It is diagonalizable over C\mathbb{C} but not over R\mathbb{R}.
  • Conjugate transpose. The matrix A∗=A‾⊤A^{*} = \overline{A}^{\top} replaces the transpose for complex vectors. Inner products in Cn\mathbb{C}^n use ⟨x,y⟩=x∗y\langle \mathbf{x}, \mathbf{y} \rangle = \mathbf{x}^{*}\mathbf{y}, and lengths use ∥v∥2=v∗v=∣v1∣2+⋯+∣vn∣2\lVert \mathbf{v} \rVert^2 = \mathbf{v}^{*}\mathbf{v} = \lvert v_1 \rvert^2 + \cdots + \lvert v_n \rvert^2.

The quarter-turn R=[0−110]R = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} has χR(t)=t2+1\chi_R(t) = t^2 + 1 and no real eigenvector. Over C\mathbb{C} it has the eigenvalue ii with eigenvector (1,−i)(1, -i), since RR sends (1,−i)(1, -i) to (i,1)=i(1,−i)(i, 1) = i(1, -i), and the eigenvalue −i-i with eigenvector (1,i)(1, i). For v=(1,i)\mathbf{v} = (1, i) the plain product v⊤v=1+i2\mathbf{v}^{\top}\mathbf{v} = 1 + i^2 is 00, while v∗v=2\mathbf{v}^{*}\mathbf{v} = 2.

Lessons Complex Eigenvalues and Real Rotations

Symmetric Matrices and Quadratic Forms

A real symmetric matrix always has an orthonormal basis of eigenvectors, so it can be diagonalized by an orthogonal change of coordinates. In those coordinates a quadratic form has no cross terms, and the signs of the eigenvalues classify it. Each eigenvalue method comes with a hypothesis that decides whether it applies.

The spectral theorem

Real spectral theorem. Let AA be a real symmetric n×nn \times n matrix, so A⊤=AA^{\top} = A. Then every eigenvalue of AA is real, and there are a real orthogonal matrix QQ and a real diagonal matrix DD with

A=QDQ⊤=λ1q1q1⊤+⋯+λnqnqn⊤,\begin{aligned} A &= QDQ^{\top} \\[0.4em] &= \lambda_1\mathbf{q}_1\mathbf{q}_1^{\top} + \cdots + \lambda_n\mathbf{q}_n\mathbf{q}_n^{\top}, \end{aligned}

where the columns qi\mathbf{q}_i of QQ are orthonormal eigenvectors and the λi\lambda_i are their eigenvalues. A real matrix is orthogonally diagonalizable in this way exactly when it is symmetric.

  • Eigenvectors of a symmetric matrix for distinct eigenvalues λ≠μ\lambda \ne \mu are orthogonal, because λ(u⋅v)=(Au)⋅v=u⋅(Av)=μ(u⋅v)\lambda(\mathbf{u} \cdot \mathbf{v}) = (A\mathbf{u}) \cdot \mathbf{v} = \mathbf{u} \cdot (A\mathbf{v}) = \mu(\mathbf{u} \cdot \mathbf{v}).
  • Inside an eigenspace of dimension 22 or more, basis vectors need not be orthogonal, so apply Gram-Schmidt there.
  • Symmetry does not make the eigenvalues positive.

Method. Check that A⊤=AA^{\top} = A, find the eigenvalues, find an orthonormal basis of each eigenspace, and place the vectors in QQ and their eigenvalues in DD in matching order. No inverse is needed, since Q−1=Q⊤Q^{-1} = Q^{\top}.

For the symmetric matrix SS with rows (2,1)(2, 1) and (1,2)(1, 2),

Q=12[111−1],D=[3001],\begin{gathered} Q = \frac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}, \\[0.4em] D = \begin{bmatrix} 3 & 0 \\ 0 & 1 \end{bmatrix}, \end{gathered}

and S=QDQ⊤S = QDQ^{\top}.

Lessons The Spectral Theorem for Symmetric Matrices

Quadratic forms

A quadratic form on Rn\mathbb{R}^n is q(x)=x⊤Axq(\mathbf{x}) = \mathbf{x}^{\top}A\mathbf{x} with AA real symmetric, the matrix of the form. A cross term k xixjk\,x_ix_j with i≠ji \ne j puts k2\frac{k}{2} in both positions (i,j)(i, j) and (j,i)(j, i), as in

ax2+2bxy+cy2=[xy][abbc][xy].\begin{aligned} &ax^2 + 2bxy + cy^2 \\[0.4em] &\quad = \begin{bmatrix} x & y \end{bmatrix}\begin{bmatrix} a & b \\ b & c \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}. \end{aligned}

A form written as x⊤Mx\mathbf{x}^{\top}M\mathbf{x} with MM not symmetric has the matrix 12(M+M⊤)\frac{1}{2}(M + M^{\top}). With A=QDQ⊤A = QDQ^{\top} and new coordinates z=Q⊤x\mathbf{z} = Q^{\top}\mathbf{x} along the principal axes, the lines spanned by the qi\mathbf{q}_i,

q(x)=λ1z12+⋯+λnzn2.q(\mathbf{x}) = \lambda_1z_1^2 + \cdots + \lambda_nz_n^2.

For n=2n = 2 and two positive eigenvalues, the level curve q=1q = 1 is an ellipse with semi-axes 1λ1\frac{1}{\sqrt{\lambda_1}} along q1\mathbf{q}_1 and 1λ2\frac{1}{\sqrt{\lambda_2}} along q2\mathbf{q}_2.

The form 2x2+2xy+2y22x^2 + 2xy + 2y^2 has matrix SS, and with s=x+y2s = \frac{x + y}{\sqrt{2}} and t=x−y2t = \frac{x - y}{\sqrt{2}} it becomes 3s2+t23s^2 + t^2. Its level curve q=1q = 1 is an ellipse with semi-axis 13\frac{1}{\sqrt{3}} along (1,1)(1, 1) and 11 along (1,−1)(1, -1).

Lessons Quadratic Forms and Positive Definiteness

Definiteness

A real symmetric matrix AA, and its form q(x)=x⊤Axq(\mathbf{x}) = \mathbf{x}^{\top}A\mathbf{x}, are classified by the signs that qq takes, and the eigenvalues decide them.

ClassCondition on qqEigenvalues
positive definiteq(x)>0q(\mathbf{x}) > 0 for every x≠0\mathbf{x} \ne \mathbf{0}all >0> 0
positive semidefiniteq(x)≥0q(\mathbf{x}) \ge 0 for every x\mathbf{x}all ≥0\ge 0
negative definiteq(x)<0q(\mathbf{x}) < 0 for every x≠0\mathbf{x} \ne \mathbf{0}all <0< 0
negative semidefiniteq(x)≤0q(\mathbf{x}) \le 0 for every x\mathbf{x}all ≤0\le 0
indefiniteqq takes both signssome >0> 0 and some <0< 0

The classes are inclusive, so a positive definite matrix is also positive semidefinite, and the zero matrix is both positive and negative semidefinite. A positive semidefinite matrix is positive definite exactly when it is invertible. For a symmetric 2×22 \times 2 matrix, both eigenvalues are positive exactly when det⁡A>0\det A > 0 and tr⁡A>0\operatorname{tr} A > 0. For every real matrix CC, the matrix C⊤CC^{\top}C is positive semidefinite, and it is positive definite exactly when CC has independent columns.

Positive entries do not make a matrix positive definite. The matrix [1221]\begin{bmatrix} 1 & 2 \\ 2 & 1 \end{bmatrix} has eigenvalues 33 and −1-1, and its form gives q(1,−1)=1−4+1=−2q(1, -1) = 1 - 4 + 1 = -2, so it is indefinite. Two vectors with values of opposite signs prove that a form is indefinite without any eigenvalue.

Lessons Quadratic Forms and Positive Definiteness

Which method applies

Check the hypothesis of a method before using it.

MethodHypothesis
A=PDP−1A = PDP^{-1} over the scalars FFnn independent eigenvectors in FnF^n
A=QDQ⊤A = QDQ^{\top} with QQ real orthogonalAA real symmetric
Ak=PDkP−1A^k = PD^kP^{-1}an eigenbasis
eigenvalue test for definitenessthe symmetric matrix of the form

Three 2×22 \times 2 matrices show the possible outcomes.

  • The matrix JJ with rows (2,1)(2, 1) and (0,2)(0, 2) has the single eigenvalue 22 with a one-dimensional eigenspace. It is defective and diagonalizable over neither R\mathbb{R} nor C\mathbb{C}.
  • The matrix [0−220]\begin{bmatrix} 0 & -2 \\ 2 & 0 \end{bmatrix} has the eigenvalues ±2i\pm 2i, no real eigenvector and a complex eigenbasis.
  • The symmetric matrix [3113]\begin{bmatrix} 3 & 1 \\ 1 & 3 \end{bmatrix} has the eigenvalues 44 and 22 with orthogonal eigenvectors (1,1)(1, 1) and (1,−1)(1, -1). It is positive definite and orthogonally diagonalizable, and its square sends e1\mathbf{e}_1 to (10,6)(10, 6).

Lessons Eigenvalues and Diagonalization Workshop

Singular Value Decomposition

Every real matrix, square or rectangular, has a singular value decomposition. It finds orthonormal input directions that the matrix sends to orthogonal outputs, which shows the rank, the four fundamental subspaces and the largest stretch at once. It also gives the pseudoinverse, the best approximations of lower rank and, for centered data, principal component analysis.

The singular value decomposition

Let AA be a real m×nm \times n matrix and q=min⁡(m,n)q = \min(m, n). A singular value decomposition is

A=UΣV⊤,A = U\Sigma V^{\top},

with UU an m×mm \times m orthogonal matrix, VV an n×nn \times n orthogonal matrix and Σ\Sigma an m×nm \times n matrix that is zero off the diagonal, with diagonal entries σ1≥σ2≥⋯≥σq≥0\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_q \ge 0, the singular values. Every real matrix has one, and the singular values are determined by AA. The columns vi\mathbf{v}_i of VV are the right singular vectors, in the input space Rn\mathbb{R}^n, and the columns ui\mathbf{u}_i of UU are the left singular vectors, in the output space Rm\mathbb{R}^m, paired by

Avi=σiui,A⊤ui=σivi,i=1,…,q.\begin{gathered} A\mathbf{v}_i = \sigma_i\mathbf{u}_i, \qquad A^{\top}\mathbf{u}_i = \sigma_i\mathbf{v}_i, \\[0.4em] i = 1, \dots, q. \end{gathered}

The squares σ12,…,σq2\sigma_1^2, \dots, \sigma_q^2 are the qq largest eigenvalues of A⊤AA^{\top}A, whose other eigenvalues, if any, are 00, and the positive ones are also the positive eigenvalues of AA⊤AA^{\top}.

QuantityRead from the SVD, with rr positive singular values
rankrank⁡A=r\operatorname{rank} A = r
Col⁡A\operatorname{Col} A and Null⁡A⊤\operatorname{Null} A^{\top}spans of u1,…,ur\mathbf{u}_1, \dots, \mathbf{u}_r and of ur+1,…,um\mathbf{u}_{r+1}, \dots, \mathbf{u}_m
Row⁡A\operatorname{Row} A and Null⁡A\operatorname{Null} Aspans of v1,…,vr\mathbf{v}_1, \dots, \mathbf{v}_r and of vr+1,…,vn\mathbf{v}_{r+1}, \dots, \mathbf{v}_n
largest stretchmax⁡∥x∥=1∥Ax∥=∥A∥2=σ1\max_{\lVert \mathbf{x} \rVert = 1} \lVert A\mathbf{x} \rVert = \lVert A \rVert_2 = \sigma_1
condition numberκ2(A)=σ1/σn\kappa_2(A) = \sigma_1 / \sigma_n for invertible AA
determinant∣det⁡A∣=σ1σ2⋯σn\lvert \det A \rvert = \sigma_1\sigma_2 \cdots \sigma_n for square AA

Singular values are in general not eigenvalues. They exist for every shape and are never negative. For a symmetric matrix they are the absolute values of the eigenvalues, so diag⁡(−3,1)\operatorname{diag}(-3, 1) has eigenvalues −3-3 and 11 but singular values 33 and 11. The two lists agree exactly for the symmetric positive semidefinite matrices.

The 2×32 \times 3 matrix AA has singular values 3\sqrt{3} and 11, with u1=12(1,1)\mathbf{u}_1 = \frac{1}{\sqrt{2}}(1, 1), u2=12(1,−1)\mathbf{u}_2 = \frac{1}{\sqrt{2}}(1, -1), v1=16(1,1,2)\mathbf{v}_1 = \frac{1}{\sqrt{6}}(1, 1, 2), v2=12(1,−1,0)\mathbf{v}_2 = \frac{1}{\sqrt{2}}(1, -1, 0) and v3=13(−1,−1,1)\mathbf{v}_3 = \frac{1}{\sqrt{3}}(-1, -1, 1). Then Av1=3 u1A\mathbf{v}_1 = \sqrt{3}\,\mathbf{u}_1, Av2=u2A\mathbf{v}_2 = \mathbf{u}_2 and Av3=0A\mathbf{v}_3 = \mathbf{0}, so the rank is 22 and v3\mathbf{v}_3 spans Null⁡A\operatorname{Null} A.

Lessons Singular Value Decomposition and Its Geometry

Computing an SVD in three forms

Algorithm. Find the eigenvalues λ1≥⋯≥λn≥0\lambda_1 \ge \cdots \ge \lambda_n \ge 0 of the symmetric matrix A⊤AA^{\top}A and an orthonormal basis of eigenvectors v1,…,vn\mathbf{v}_1, \dots, \mathbf{v}_n in the same order. Set σi=λi\sigma_i = \sqrt{\lambda_i} for i≤qi \le q and, for each positive σi\sigma_i,

ui=1σiAvi.\mathbf{u}_i = \frac{1}{\sigma_i}A\mathbf{v}_i.

These ui\mathbf{u}_i are automatically orthonormal. For a full SVD, complete them with an orthonormal basis of Null⁡A⊤\operatorname{Null} A^{\top}. When m<nm < n it is quicker to start from AA⊤AA^{\top}, which has the same positive eigenvalues with the same multiplicities, set vi=1σiA⊤ui\mathbf{v}_i = \frac{1}{\sigma_i}A^{\top}\mathbf{u}_i, and complete the vi\mathbf{v}_i with an orthonormal basis of Null⁡A\operatorname{Null} A. Compute the second vector of each pair from the first, never separately, since independent sign choices can break Avi=σiuiA\mathbf{v}_i = \sigma_i\mathbf{u}_i.

FormUUΣ\SigmaVVSingular values kept
Fullm×mm \times mm×nm \times nn×nn \times nall qq, padded with zero rows or columns
Economym×qm \times qq×qq \times qn×qn \times qall qq, zeros included
Compactm×rm \times rr×rr \times rn×rn \times ronly the rr positive ones

All three products equal AA, the compact one when r≥1r \ge 1. The rectangular factors have orthonormal columns, so Ur⊤Ur=IrU_r^{\top}U_r = I_r, while UrUr⊤U_rU_r^{\top} is the orthogonal projection onto Col⁡A\operatorname{Col} A and not the identity unless r=mr = m. Books and software use the names reduced and thin for different forms, so check the sizes. A proposed full SVD is correct when the factors have the sizes of the full form, U⊤U=ImU^{\top}U = I_m, V⊤V=InV^{\top}V = I_n, Σ\Sigma is zero off the diagonal, the σi\sigma_i are nonnegative and decreasing, Avi=σiuiA\mathbf{v}_i = \sigma_i\mathbf{u}_i for i≤qi \le q and Avi=0A\mathbf{v}_i = \mathbf{0} for q<i≤nq < i \le n. Singular vectors are not unique. A pair (ui,vi)(\mathbf{u}_i, \mathbf{v}_i) can change sign together, and for a repeated positive singular value the right singular vectors can be any orthonormal basis of their subspace, with the partners computed from them.

The rank-one matrix

B=[020000]B = \begin{bmatrix} 0 & 2 \\ 0 & 0 \\ 0 & 0 \end{bmatrix}

has σ1=2\sigma_1 = 2 and σ2=0\sigma_2 = 0. A full SVD uses U=I3U = I_3, V=[e2e1]V = \begin{bmatrix} \mathbf{e}_2 & \mathbf{e}_1 \end{bmatrix} and the 3×23 \times 2 matrix Σ\Sigma with diagonal entries 22 and 00. The economy form keeps the zero singular value in the 2×22 \times 2 factor diag⁡(2,0)\operatorname{diag}(2, 0), while the compact form is B=2 e1e2⊤B = 2\,\mathbf{e}_1\mathbf{e}_2^{\top}, with e1\mathbf{e}_1 in R3\mathbb{R}^3 and e2\mathbf{e}_2 in R2\mathbb{R}^2.

Lessons Computing an SVD in Full, Economy and Compact Forms

Pseudoinverses and minimum-norm solutions

For an SVD A=UΣV⊤A = U\Sigma V^{\top} of rank rr, the pseudoinverse of Σ\Sigma is the n×mn \times m matrix Σ+\Sigma^{+} with diagonal entries 1σ1,…,1σr\frac{1}{\sigma_1}, \dots, \frac{1}{\sigma_r} followed by zeros, and the pseudoinverse of AA is the n×mn \times m matrix

A+=VΣ+U⊤.A^{+} = V\Sigma^{+}U^{\top}.

For r≥1r \ge 1 the compact SVD gives the same matrix, A+=VrΣr−1Ur⊤A^{+} = V_r\Sigma_r^{-1}U_r^{\top}. For every b\mathbf{b}, the vector A+bA^{+}\mathbf{b} is the least-squares solution of Ax=bA\mathbf{x} = \mathbf{b} of smallest norm, the unique one in Row⁡A\operatorname{Row} A. When the system is consistent it is the minimum-norm solution x+\mathbf{x}^{+}, and every other solution adds a null-space component h\mathbf{h}, with ∥x++h∥2=∥x+∥2+∥h∥2\lVert \mathbf{x}^{+} + \mathbf{h} \rVert^2 = \lVert \mathbf{x}^{+} \rVert^2 + \lVert \mathbf{h} \rVert^2.

CasePseudoinverse
AA square and invertibleA+=A−1A^{+} = A^{-1}
full column rank, r=nr = nA+=(A⊤A)−1A⊤A^{+} = (A^{\top}A)^{-1}A^{\top}
full row rank, r=mr = mA+=A⊤(AA⊤)−1A^{+} = A^{\top}(AA^{\top})^{-1}
every AAAA+AA^{+} is the orthogonal projection onto Col⁡A\operatorname{Col} A and A+AA^{+}A the one onto Row⁡A\operatorname{Row} A

The pseudoinverse inverts only the positive singular values. It cannot recover a null-space component that the measurements never saw, and setting small positive singular values to zero is a different procedure, truncation, which needs its own stated criterion. The minimum norm is measured in the given units of the unknowns, so rescaling them can change the answer.

For the 2×32 \times 3 matrix AA, which has full row rank,

A+=13[2−1−1211].A^{+} = \frac{1}{3}\begin{bmatrix} 2 & -1 \\ -1 & 2 \\ 1 & 1 \end{bmatrix}.

With b=(4,3)\mathbf{b} = (4, 3) it gives x+=(53,23,73)\mathbf{x}^{+} = (\tfrac{5}{3}, \tfrac{2}{3}, \tfrac{7}{3}), the member t=73t = \frac{7}{3} of the solution family (4−t,3−t,t)(4 - t, 3 - t, t) and the only one orthogonal to (−1,−1,1)(-1, -1, 1). For the single equation x+y=2x + y = 2 the minimum-norm solution is (1,1)(1, 1).

Lessons Pseudoinverses and Minimum-Norm Solutions

Low-rank approximation

The outer product of x\mathbf{x} in Rm\mathbb{R}^m and y\mathbf{y} in Rn\mathbb{R}^n is the m×nm \times n matrix xy⊤\mathbf{x}\mathbf{y}^{\top}, with entries xiyjx_iy_j and (xy⊤)z=(y⋅z) x(\mathbf{x}\mathbf{y}^{\top})\mathbf{z} = (\mathbf{y} \cdot \mathbf{z})\,\mathbf{x}. For nonzero factors it has rank one, and every rank-one matrix has this form. An SVD writes a matrix of rank rr as a sum of rank-one layers, and the truncated SVD keeps the first kk,

A=∑i=1rσiuivi⊤,Ak=∑i=1kσiuivi⊤.\begin{gathered} A = \sum_{i=1}^{r} \sigma_i\mathbf{u}_i\mathbf{v}_i^{\top}, \\[0.4em] A_k = \sum_{i=1}^{k} \sigma_i\mathbf{u}_i\mathbf{v}_i^{\top}. \end{gathered}

The Frobenius norm is the length of the list of all entries, and the spectral norm is the largest stretch,

∥A∥F=(∑i,jaij2)1/2=σ12+⋯+σr2,∥A∥2=σ1.\begin{aligned} \lVert A \rVert_F &= \Big(\sum_{i,j} a_{ij}^2\Big)^{1/2} \\[0.4em] &= \sqrt{\sigma_1^2 + \cdots + \sigma_r^2}, \\[0.4em] \lVert A \rVert_2 &= \sigma_1. \end{aligned}

Eckart-Young theorem. For 0≤k<r0 \le k < r and every m×nm \times n matrix BB of rank at most kk,

∥A−B∥2≥∥A−Ak∥2=σk+1,∥A−B∥F≥∥A−Ak∥F=(∑i=k+1rσi2)1/2.\begin{aligned} \lVert A - B \rVert_2 &\ge \lVert A - A_k \rVert_2 = \sigma_{k+1}, \\[0.4em] \lVert A - B \rVert_F &\ge \lVert A - A_k \rVert_F \\[0.4em] &= \Big(\sum_{i=k+1}^{r} \sigma_i^2\Big)^{1/2}. \end{aligned}

So AkA_k is a best approximation of rank at most kk in both norms. For 1≤k<r1 \le k < r it is the only best approximation in the Frobenius norm when σk>σk+1\sigma_k > \sigma_{k+1}. When σk=σk+1\sigma_k = \sigma_{k+1}, a tie at the cutoff, different choices of singular vectors give different truncations that are equally good. Storing AkA_k takes k(m+n+1)k(m + n + 1) numbers instead of mnmn.

For the 2×32 \times 3 matrix AA, the first layer is

A1=3 u1v1⊤=12[112112],A_1 = \sqrt{3}\,\mathbf{u}_1\mathbf{v}_1^{\top} = \frac{1}{2}\begin{bmatrix} 1 & 1 & 2 \\ 1 & 1 & 2 \end{bmatrix},

and both errors equal σ2=1\sigma_2 = 1, while ∥A∥F=3+1=2\lVert A \rVert_F = \sqrt{3 + 1} = 2.

Lessons Outer Products and Low-Rank Approximation

Principal component analysis

Put N>1N > 1 observations of pp features in the rows x1⊤,…,xN⊤\mathbf{x}_1^{\top}, \dots, \mathbf{x}_N^{\top} of an N×pN \times p data matrix XX, and let xˉ=1N(x1+⋯+xN)\bar{\mathbf{x}} = \frac{1}{N}(\mathbf{x}_1 + \cdots + \mathbf{x}_N) be the mean vector in Rp\mathbb{R}^p. The centered data matrix and the sample covariance matrix are

Xc=X−1xˉ⊤,C=1N−1Xc⊤Xc,\begin{gathered} X_c = X - \mathbf{1}\bar{\mathbf{x}}^{\top}, \\[0.4em] C = \frac{1}{N - 1}X_c^{\top}X_c, \end{gathered}

where 1\mathbf{1} is the vector of ones in RN\mathbb{R}^N. The p×pp \times p matrix CC is symmetric and positive semidefinite, its diagonal holds the feature variances, and its trace is the total variance.

  • Projected variance. For a unit vector w\mathbf{w} the scores XcwX_c\mathbf{w} have sample variance w⊤Cw\mathbf{w}^{\top}C\mathbf{w}.
  • Principal components. Let CC have eigenvalues λ1≥⋯≥λp≥0\lambda_1 \ge \cdots \ge \lambda_p \ge 0 with orthonormal eigenvectors w1,…,wp\mathbf{w}_1, \dots, \mathbf{w}_p. The direction w1\mathbf{w}_1 maximizes the projected variance, which then equals λ1\lambda_1, and each wk\mathbf{w}_k does the same among unit vectors orthogonal to the earlier ones.
  • Retained variance. Keeping kk directions retains λ1+⋯+λk\lambda_1 + \cdots + \lambda_k of the total tr⁡C\operatorname{tr} C. With Wk=[ w1 ⋯ wk ]W_k = [\,\mathbf{w}_1 \ \cdots \ \mathbf{w}_k\,], the reconstructions xˉ+WkWk⊤(xi−xˉ)\bar{\mathbf{x}} + W_kW_k^{\top}(\mathbf{x}_i - \bar{\mathbf{x}}) have total squared error (N−1)(λk+1+⋯+λp)(N - 1)(\lambda_{k+1} + \cdots + \lambda_p), the smallest possible for kk directions through the mean.
  • Through the SVD. If Xc=UΣV⊤X_c = U\Sigma V^{\top}, the right singular vectors are principal directions, λi=σi2N−1\lambda_i = \frac{\sigma_i^2}{N - 1}, and the scores on the first kk components are UkΣkU_k\Sigma_k.
  • Choices. Without centering, a large rank-one term along the mean can dominate. Measuring a feature in other units rescales its column, which can change CC, its eigenvectors and their order. Standardizing every feature is one such rescaling, not an automatic correction. A large variance does not show that a direction matters for a given question.

The four observations (2,1)(2, 1), (2,−1)(2, -1), (−2,1)(-2, 1), (−2,−1)(-2, -1) have mean 0\mathbf{0} and C=diag⁡(163,43)C = \operatorname{diag}(\tfrac{16}{3}, \tfrac{4}{3}). The first principal direction e1\mathbf{e}_1 retains 1620=45\frac{16}{20} = \frac{4}{5} of the total variance, and the one-dimensional reconstruction has squared error 3⋅43=43 \cdot \frac{4}{3} = 4.

Lessons Principal Component Analysis with Centering and Variance

Applications and Review

The course closes with flows in a network and with problems of fitting and reconstruction from measurements. An incidence matrix turns conservation at each node into a linear system whose kernel describes circulation around cycles. Fitting and reconstruction ask different questions of a matrix, and each answer needs its own checks.

Network flows

A directed graph with nn nodes and mm edges has the n×mn \times m incidence matrix BB with bik=1b_{ik} = 1 when edge kk leaves node ii, bik=−1b_{ik} = -1 when it enters node ii, and bik=0b_{ik} = 0 otherwise. For edge flows f\mathbf{f} in Rm\mathbb{R}^m and net supplies s\mathbf{s} in Rn\mathbb{R}^n, positive at a source and negative where material is consumed, conservation at every node reads

Bf=s.B\mathbf{f} = \mathbf{s}.

A negative flow runs against the arrow of its edge.

FactCondition
s1+⋯+sn=0s_1 + \cdots + s_n = 0 is necessaryalways, since every column of BB sums to 00
the same condition is also sufficientconnected graph and signed flows
rank⁡B=n−1\operatorname{rank} B = n - 1 and Null⁡B⊤=span⁡{1}\operatorname{Null} B^{\top} = \operatorname{span}\{\mathbf{1}\}connected graph
dim⁡Null⁡B=m−n+1\dim \operatorname{Null} B = m - n + 1, spanned by circulations around cyclesconnected graph
all solutions are f0+z\mathbf{f}_0 + \mathbf{z} with z\mathbf{z} in Null⁡B\operatorname{Null} Bone solution f0\mathbf{f}_0 known

A circulation puts 11 on the edges of a cycle traversed along their arrows and −1-1 on those traversed against them, and it changes no node balance. Requiring f≥0\mathbf{f} \ge \mathbf{0} adds inequalities that the linear system does not imply, and the feasible set can shrink to a segment, a single point or nothing.

For the edges 1→21 \to 2, 2→32 \to 3 and 1→31 \to 3,

B=[101−1100−1−1].B = \begin{bmatrix} 1 & 0 & 1 \\ -1 & 1 & 0 \\ 0 & -1 & -1 \end{bmatrix}.

The supplies s=(3,−1,−2)\mathbf{s} = (3, -1, -2) add up to 00, and every solution is f=(t,t−1,3−t)\mathbf{f} = (t, t - 1, 3 - t), which moves along the circulation (1,1,−1)(1, 1, -1) as tt changes. Nonnegative flows need 1≤t≤31 \le t \le 3.

Lessons Network Flows, Conservation and Cycles

Fitting and reconstruction

SituationGoalMethodCheck
b\mathbf{b} not in Col⁡A\operatorname{Col} A, often m>nm > nfit the dataleast squares by normal equations, QR or SVDA⊤r=0A^{\top}\mathbf{r} = \mathbf{0}, then Null⁡A\operatorname{Null} A for uniqueness
consistent, with Null⁡A≠{0}\operatorname{Null} A \ne \{\mathbf{0}\}, which always holds when m<nm < nchoose one inputthe minimum-norm solution A+bA^{+}\mathbf{b}Ax+=bA\mathbf{x}^{+} = \mathbf{b} and x+\mathbf{x}^{+} orthogonal to Null⁡A\operatorname{Null} A

The count of equations settles nothing by itself. An overdetermined system can still be consistent, and an underdetermined one can be inconsistent. A consistent underdetermined system has the solutions xp+Null⁡A\mathbf{x}_p + \operatorname{Null} A with dim⁡Null⁡A≥n−m>0\dim \operatorname{Null} A \ge n - m > 0, and the data cannot tell them apart. An exact new measurement a⊤x=β\mathbf{a}^{\top}\mathbf{x} = \beta with a\mathbf{a} outside Row⁡A\operatorname{Row} A raises the rank and lowers the nullity by one. A small or zero residual shows agreement with the data used, not a validated model, which needs new observations and justified assumptions.

Fitting a+bta + bt to the points (0,1)(0, 1), (1,2)(1, 2), (2,4)(2, 4) gives a=56a = \frac{5}{6} and b=32b = \frac{3}{2}, with residuals (16,−13,16)(\tfrac{1}{6}, -\tfrac{1}{3}, \tfrac{1}{6}) and squared error 16\frac{1}{6}. For the 2×32 \times 3 matrix AA and b=(4,3)\mathbf{b} = (4, 3), the minimum-norm reconstruction is (53,23,73)(\tfrac{5}{3}, \tfrac{2}{3}, \tfrac{7}{3}), and an added exact measurement x3=2x_3 = 2 selects the solution (2,1,2)(2, 1, 2) instead.

Lessons Linear Algebra Review with Fitting and Reconstruction