MATH-125 · Lesson 3 of 5 · 36 min
Matrix algebra
In Lesson 2 a matrix was a convenient table for bookkeeping. In this chapter it becomes an object in its own right, with its own arithmetic. Matrices can be added, multiplied and (sometimes) inverted, and once you can do that, a system of a thousand equations can be written as the single line \(A\mathbf{x} = \mathbf{b}\) and reasoned about as easily as \(ax = b\).
Matrices also act. Multiplying a vector by a matrix rotates, stretches, shears or projects it. This view of a matrix as a transformation is behind computer graphics, robot kinematics, coordinate changes in stress analysis and the stiffness method in structural engineering. By the end of this chapter you will be able to set up and solve a small stiffness model yourself.
Matrices and notation
An \(m \times n\) matrix is a rectangular array with \(m\) rows and \(n\) columns. The entry in row \(i\), column \(j\) is written \(a_{ij}\). Rows come first, always: a 2×3 matrix has 2 rows and 3 columns.
A matrix with one column is a column vector, and that is how vectors are written in linear algebra from now on. A square matrix has as many rows as columns. Its main diagonal runs from top left to bottom right. Some special square matrices have names:
- The identity matrix \(I\) has 1s on the diagonal and 0s elsewhere. It plays the role of the number 1.
- A diagonal matrix has non-zero entries only on the diagonal.
- An upper triangular matrix has zeros below the diagonal, like the echelon forms in Lesson 2.
- A symmetric matrix equals its own transpose: \(a_{ij} = a_{ji}\).
Addition and scalar multiplication
Matrices of the same size add entry by entry, and a scalar multiplies every entry. These operations behave just like ordinary arithmetic: \(A + B = B + A\), \(c(A + B) = cA + cB\), and so on.
You cannot add matrices of different sizes. A 2×3 plus a 3×2 is undefined.
Multiplying a matrix by a vector
The product \(A\mathbf{x}\) can be read in two ways, and both are worth knowing.
By rows: each entry of \(A\mathbf{x}\) is the dot product of a row of \(A\) with \(\mathbf{x}\). This is how you compute it, and it is why \(A\mathbf{x} = \mathbf{b}\) is the same as the system of equations: row \(i\) dotted with \(\mathbf{x}\) equals \(b_i\).
By columns: \(A\mathbf{x}\) is a combination of the columns of \(A\), weighted by the entries of \(\mathbf{x}\):
The column view explains what solving \(A\mathbf{x} = \mathbf{b}\) means: finding the amounts of each column that combine to give \(\mathbf{b}\). It also explains the transformation picture. The first column of \(A\) is where \(A\) sends \((1, 0)\), and the second column is where it sends \((0, 1)\). Knowing those two images tells you where every other vector goes.
Worked problem
Rotation
Find the matrix that rotates vectors 30° counterclockwise, and use it to rotate \((2, 0)\).
Show solution
- Rotating \((1, 0)\) by \(\theta\) gives \((\cos\theta, \sin\theta)\). Rotating \((0, 1)\) gives \((-\sin\theta, \cos\theta)\). These are the columns:
- \[R_\theta = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}, \qquad R_{30^\circ} = \begin{pmatrix} 0.8660 & -0.5 \\ 0.5 & 0.8660 \end{pmatrix}\]
- Multiply: \(R_{30^\circ}\begin{pmatrix} 2 \\ 0 \end{pmatrix} = \begin{pmatrix} 1.732 \\ 1 \end{pmatrix}\).
- Check: the length is still \(\sqrt{3 + 1} = 2\). Rotations never change lengths.
Answer: (1.732, 1)
Matrix multiplication
The product \(AB\) is defined when the number of columns of \(A\) equals the number of rows of \(B\). If \(A\) is \(m \times n\) and \(B\) is \(n \times p\), then \(AB\) is \(m \times p\). The entry in row \(i\), column \(j\) of \(AB\) is the dot product of row \(i\) of \(A\) with column \(j\) of \(B\):
A quick size check before you start: write the sizes side by side, \((m \times n)(n \times p)\). The inner numbers must match, and the outer numbers give the size of the answer.
Worked problem
A rectangular product
Compute \(CD\) and \(DC\) for \(C = \begin{pmatrix} 1 & 0 & 2 \\ -1 & 3 & 1 \end{pmatrix}\) and \(D = \begin{pmatrix} 3 & 1 \\ 2 & 1 \\ 1 & 0 \end{pmatrix}\).
Show solution
- \(C\) is 2×3 and \(D\) is 3×2, so \(CD\) is 2×2 and \(DC\) is 3×3.
- Row 1 of \(C\) with column 1 of \(D\): \(1\cdot3 + 0\cdot2 + 2\cdot1 = 5\). With column 2: \(1 + 0 + 0 = 1\).
- Row 2 of \(C\): with column 1, \(-3 + 6 + 1 = 4\); with column 2, \(-1 + 3 + 0 = 2\).
- \[CD = \begin{pmatrix} 5 & 1 \\ 4 & 2 \end{pmatrix}, \qquad DC = \begin{pmatrix} 2 & 3 & 7 \\ 1 & 3 & 5 \\ 1 & 0 & 2 \end{pmatrix}\]
Answer: CD is 2×2 and DC is 3×3: not even the same size
Order matters
Matrix multiplication is not commutative. Usually \(AB \ne BA\), even when both are defined and the same size.
Worked problem
AB versus BA
Compute \(AB\) and \(BA\) for \(A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\) and \(B = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\).
Show solution
- \(AB = \begin{pmatrix} 1\cdot0 + 2\cdot1 & 1\cdot1 + 2\cdot0 \\ 3\cdot0 + 4\cdot1 & 3\cdot1 + 4\cdot0 \end{pmatrix} = \begin{pmatrix} 2 & 1 \\ 4 & 3 \end{pmatrix}\). Multiplying by \(B\) on the right swapped the columns of \(A\).
- \(BA = \begin{pmatrix} 3 & 4 \\ 1 & 2 \end{pmatrix}\). Multiplying by \(B\) on the left swapped the rows.
Answer: AB ≠ BA
The transformation view explains why. \(AB\mathbf{x}\) means "apply \(B\) first, then \(A\)". Rotating then stretching is not the same as stretching then rotating. For instance, with \(R\) a 90° rotation and \(S\) a horizontal stretch by 2, \(SR = \begin{pmatrix} 0 & -2 \\ 1 & 0 \end{pmatrix}\) but \(RS = \begin{pmatrix} 0 & -1 \\ 2 & 0 \end{pmatrix}\).
Apart from commutativity, the familiar rules survive: \((AB)C = A(BC)\), \(A(B + C) = AB + AC\), and \(AI = IA = A\). Two other surprises: \(AB = 0\) is possible with neither \(A\) nor \(B\) zero, and \(AB = AC\) does not let you cancel \(A\) unless \(A\) is invertible.
The transpose
The transpose \(A^T\) swaps rows and columns: \((A^T)_{ij} = a_{ji}\). A 2×3 matrix has a 3×2 transpose. Its rules:
- \((A^T)^T = A\) and \((A + B)^T = A^T + B^T\).
- \((AB)^T = B^T A^T\). The order reverses, like taking off socks and shoes.
- The dot product is a matrix product: \(\mathbf{u}\cdot\mathbf{v} = \mathbf{u}^T\mathbf{v}\).
Symmetric matrices (\(A^T = A\)) are everywhere in engineering: stiffness matrices, stress tensors, inertia tensors, covariance matrices. For any matrix \(A\), the product \(A^TA\) is square and symmetric; it is the heart of least-squares curve fitting.
The inverse
For numbers, the solution of \(ax = b\) is \(x = a^{-1}b\), provided \(a \ne 0\). The matrix version is the inverse. A square matrix \(A\) is invertible if there is a matrix \(A^{-1}\) with
Then \(A\mathbf{x} = \mathbf{b}\) has the unique solution \(\mathbf{x} = A^{-1}\mathbf{b}\). A matrix without an inverse is called singular. Only square matrices can have inverses, and many square matrices do not, just as 0 has no reciprocal.
2×2 inverses
For a 2×2 matrix there is a formula worth memorizing:
Swap the diagonal entries, negate the off-diagonal ones, and divide by \(ad - bc\). That number is the determinant, the subject of Lesson 4. If it is zero, there is no inverse.
Worked problem
Inverse and solution
Find the inverse of \(A = \begin{pmatrix} 4 & 7 \\ 2 & 6 \end{pmatrix}\) and use it to solve \(4x + 7y = 1\), \(2x + 6y = 2\).
Show solution
- \(ad - bc = 24 - 14 = 10\).
- \[A^{-1} = \frac{1}{10}\begin{pmatrix} 6 & -7 \\ -2 & 4 \end{pmatrix} = \begin{pmatrix} 0.6 & -0.7 \\ -0.2 & 0.4 \end{pmatrix}\]
- Check: \(AA^{-1}\) has top-left entry \(4(0.6) + 7(-0.2) = 2.4 - 1.4 = 1\). The others work out similarly.
- \(\mathbf{x} = A^{-1}\mathbf{b} = \begin{pmatrix} 0.6 - 1.4 \\ -0.2 + 0.8 \end{pmatrix} = \begin{pmatrix} -0.8 \\ 0.6 \end{pmatrix}\).
Answer: x = −0.8, y = 0.6
Larger inverses by Gauss–Jordan
For bigger matrices, write \(A\) and \(I\) side by side as \([A \mid I]\) and apply Gauss–Jordan elimination to the whole thing. When the left side becomes \(I\), the right side is \(A^{-1}\). If the left side develops a row of zeros, \(A\) is singular.
Worked problem
A 3×3 inverse
Find the inverse of \(B = \begin{pmatrix} 2 & 0 & 1 \\ 1 & 1 & 0 \\ 0 & 1 & 1 \end{pmatrix}\).
Show solution
- Start with \([B \mid I]\). Swap \(R_1\) and \(R_2\) to get a 1 as the first pivot.
- \(R_2 \to R_2 - 2R_1\): row 2 becomes \([0, -2, 1 \mid 1, -2, 0]\).
- Swap \(R_2\) and \(R_3\), then \(R_3 \to R_3 + 2R_2\): row 3 becomes \([0, 0, 3 \mid 1, -2, 2]\). Divide it by 3.
- Clear upward: \(R_2 \to R_2 - R_3\) gives \([0, 1, 0 \mid -\tfrac13, \tfrac23, \tfrac13]\). Then \(R_1 \to R_1 - R_2\) gives \([1, 0, 0 \mid \tfrac13, \tfrac13, -\tfrac13]\).
- \[B^{-1} = \frac13\begin{pmatrix} 1 & 1 & -1 \\ -1 & 2 & 1 \\ 1 & -2 & 2 \end{pmatrix}\]
- Check one entry of \(BB^{-1}\): row 1 of \(B\) with column 1 of \(B^{-1}\) is \(\tfrac13(2 + 0 + 1) = 1\).
Answer: B⁻¹ = (1/3)[[1, 1, −1], [−1, 2, 1], [1, −2, 2]]
Inverse rules, and when not to use one
If \(A\) and \(B\) are invertible, then \((AB)^{-1} = B^{-1}A^{-1}\) (order reverses again) and \((A^T)^{-1} = (A^{-1})^T\).
In practice, engineers rarely compute an inverse to solve a system. Elimination solves \(A\mathbf{x} = \mathbf{b}\) with about a third of the work of finding \(A^{-1}\), and with less rounding error. Software factors \(A = LU\) (a lower triangular matrix times an upper triangular one, which is just elimination written down) and reuses the factors for each new right-hand side. The inverse is still essential as an idea: it tells you whether a unique solution exists and gives formulas such as \(\mathbf{x} = A^{-1}\mathbf{b}\) for analysis.
Application: a stiffness model
The stiffness method, the basis of structural analysis software and the finite-element method, writes the equilibrium of a structure as \(K\mathbf{u} = \mathbf{F}\). Here \(\mathbf{u}\) lists the unknown displacements of the nodes, \(\mathbf{F}\) the applied forces, and \(K\) is the stiffness matrix.
Worked problem
Two springs in series
Springs \(k_1 = 100\) N/m and \(k_2 = 50\) N/m are connected as shown, with a 10 N force at node 2. Find the node displacements.
Show solution
- Spring 1 stretches by \(u_1\) and pulls node 1 back with \(k_1u_1\). Spring 2 stretches by \(u_2 - u_1\) and pulls the two nodes toward each other with \(k_2(u_2 - u_1)\).
- Node 1 equilibrium: \(-k_1u_1 + k_2(u_2 - u_1) = 0\). Node 2: \(-k_2(u_2 - u_1) + F = 0\).
- In matrix form:
- \[\begin{pmatrix} k_1 + k_2 & -k_2 \\ -k_2 & k_2 \end{pmatrix}\begin{pmatrix} u_1 \\ u_2 \end{pmatrix} = \begin{pmatrix} 0 \\ F \end{pmatrix} \;\Rightarrow\; \begin{pmatrix} 150 & -50 \\ -50 & 50 \end{pmatrix}\begin{pmatrix} u_1 \\ u_2 \end{pmatrix} = \begin{pmatrix} 0 \\ 10 \end{pmatrix}\]
- Determinant \(150 \times 50 - 50 \times 50 = 5000\). Using the 2×2 inverse: \(u_1 = \dfrac{50 \cdot 0 + 50 \cdot 10}{5000} = 0.1\) m and \(u_2 = \dfrac{50 \cdot 0 + 150 \cdot 10}{5000} = 0.3\) m.
- Check with physics: both springs carry the full 10 N. Spring 1 stretches \(10/100 = 0.1\) m and spring 2 stretches \(10/50 = 0.2\) m, so \(u_2 = 0.3\) m.
Answer: u₁ = 0.1 m, u₂ = 0.3 m
Notice that \(K\) is symmetric, as stiffness matrices always are. If the wall were removed, \(K\) would become \(\begin{pmatrix} k_2 & -k_2 \\ -k_2 & k_2 \end{pmatrix}\), which is singular: an unsupported structure can slide freely, so there is no unique displacement. Software that reports a "singular stiffness matrix" is telling you the model is missing a support.
Common mistakes
MistakeMultiplying matrices entry by entry.
InsteadEach entry of AB is a row of A dotted with a column of B.
MistakeMultiplying matrices whose inner sizes do not match, or getting the size of the answer wrong.
InsteadWrite (m × n)(n × p): the inner numbers must agree, and the answer is m × p.
MistakeAssuming AB = BA, or "canceling" A from AB = AC.
InsteadOrder matters, and canceling needs A to be invertible.
MistakeWriting (AB)⁻¹ = A⁻¹B⁻¹ or (AB)ᵀ = AᵀBᵀ.
InsteadBoth reverse the order: (AB)⁻¹ = B⁻¹A⁻¹ and (AB)ᵀ = BᵀAᵀ.
MistakeIn the 2×2 inverse formula, negating the diagonal and swapping the off-diagonal entries.
InsteadSwap the diagonal (a ↔ d), negate the off-diagonal (−b, −c), then divide by ad − bc.
MistakeWriting a matrix's images of the basis vectors as rows.
InsteadThe image of the j-th basis vector is the j-th column.
Summary and key terms
- An m × n matrix has m rows and n columns. Same-size matrices add entry by entry.
- Ax is a combination of the columns of A. The columns are the images of the basis vectors, which is how to build a transformation matrix.
- In AB each entry is a row of A dotted with a column of B; inner sizes must match. Order matters: AB usually differs from BA.
- The transpose swaps rows and columns; (AB)ᵀ = BᵀAᵀ. Symmetric matrices satisfy Aᵀ = A.
- The inverse satisfies AA⁻¹ = I. For 2×2: swap the diagonal, negate the off-diagonal, divide by ad − bc. For larger matrices, row-reduce [A | I].
- A singular matrix has no inverse. In practice, solve systems by elimination (LU) rather than computing the inverse.
- The stiffness method writes structural equilibrium as Ku = F with a symmetric stiffness matrix K.
- Matrix
- A rectangular array of numbers, sized rows × columns.
- Identity matrix
- I: 1s on the diagonal, 0s elsewhere; AI = IA = A.
- Transpose
- Aᵀ, the matrix with rows and columns swapped.
- Symmetric matrix
- A matrix equal to its transpose.
- Linear transformation
- A map of vectors given by multiplication by a matrix.
- Inverse
- A⁻¹ with AA⁻¹ = A⁻¹A = I.
- Singular
- Having no inverse.
- LU factorization
- Writing A as a lower triangular matrix times an upper triangular matrix; elimination recorded for reuse.
- Stiffness matrix
- K in Ku = F, relating node displacements to forces.
Practice problems
Work each problem on paper first, then reveal the answer to check.
Compute \(\begin{pmatrix} 1 & -2 \\ 0 & 3 \end{pmatrix}\begin{pmatrix} 4 \\ 1 \end{pmatrix}\) both by rows and as a combination of columns.
Show answer
Rows: (4 − 2, 0 + 3) = (2, 3). Columns: 4(1, 0) + 1(−2, 3) = (2, 3).
If \(A\) is 3×4 and \(B\) is 4×2, which of \(AB\), \(BA\), \(A^TB\), \(B^TA^T\) are defined, and what size are they?
Show answer
AB: 3×2. BA: undefined (2 ≠ 3). AᵀB: 4×3 times 4×2, undefined. BᵀAᵀ: 2×4 times 4×3 = 2×3 (it equals (AB)ᵀ).
Compute \(\begin{pmatrix} 2 & 1 \\ 0 & 1 \end{pmatrix}\begin{pmatrix} 1 & 3 \\ -1 & 2 \end{pmatrix}\).
Show answer
[[2 − 1, 6 + 2], [0 − 1, 0 + 2]] = [[1, 8], [−1, 2]].
Write the matrix that reflects vectors in the \(x\)-axis, and the matrix that rotates them by 90° counterclockwise.
Show answer
Reflection: (1, 0) → (1, 0), (0, 1) → (0, −1), so [[1, 0], [0, −1]]. Rotation: (1, 0) → (0, 1), (0, 1) → (−1, 0), so [[0, −1], [1, 0]].
Find a pair of non-zero 2×2 matrices with \(AB = 0\).
Show answer
One example: A = [[1, 0], [0, 0]], B = [[0, 0], [0, 1]]. Their product is the zero matrix.
Find the inverse of \(\begin{pmatrix} 3 & 1 \\ 5 & 2 \end{pmatrix}\).
Show answer
ad − bc = 6 − 5 = 1. Inverse [[2, −1], [−5, 3]].
For which \(k\) is \(\begin{pmatrix} 2 & k \\ 6 & 9 \end{pmatrix}\) singular?
Show answer
18 − 6k = 0, so k = 3. Then the rows are proportional.
Use the inverse in the 3×3 example to solve \(B\mathbf{x} = (3, 2, 2)\).
Show answer
x = (1/3)(3 + 2 − 2, −3 + 4 + 2, 3 − 4 + 4) = (1, 1, 1). Check: B(1, 1, 1) = (3, 2, 2).
Show that \((A^TA)^T = A^TA\) for any matrix \(A\).
Show answer
(AᵀA)ᵀ = Aᵀ(Aᵀ)ᵀ = AᵀA, using (XY)ᵀ = YᵀXᵀ. So AᵀA is symmetric.
Repeat the spring example with \(k_1 = 200\) N/m, \(k_2 = 100\) N/m and \(F = 30\) N.
Show answer
K = [[300, −100], [−100, 100]], det 20 000. u₁ = 100 × 30/20 000 = 0.15 m, u₂ = 300 × 30/20 000 = 0.45 m. Check: 30/200 = 0.15, 30/100 = 0.30, total 0.45.
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.