Linear Algebra — 01 · Matrix Algebra, Inverses and LU Factorization
In Linear Algebra 00 a matrix was only a compact way to write a system of equations. This post treats matrices as objects with their own algebra: they can be added, multiplied, transposed and — sometimes — inverted. Matrix multiplication is the operation that makes all of this interesting, so it gets four separate readings, each useful in a different situation. Then row operations become matrices themselves (elementary matrices), which turns Gaussian elimination into an algebraic statement: , a lower triangular matrix times an upper triangular one, or when rows must be exchanged. This factorization is how real software solves , and it explains a rule every numerical programmer learns early: do not compute to solve a linear system.
Series map: 00 Vectors & Linear Systems → 01 Matrix Algebra, Inverses & LU (this post) → 02 Vector Spaces, Basis & Dimension → 03 Linear Maps, Change of Basis & Determinants → 04 Eigenvalues & Diagonalization → 05 Inner Products, Spectral Theorem & SVD.
Learning Outcome
- Multiply matrices in four ways — entry by entry, by columns, by rows, and as a sum of outer products — and know when each view is the helpful one.
- Explain why in general, and name other rules from ordinary algebra that fail for matrices.
- Use the transpose rules, including , and recognise symmetric, triangular and permutation matrices.
- Multiply block (partitioned) matrices and do one step of block elimination.
- Write each row operation as an elementary matrix and invert it.
- Define the inverse, use the formula, and compute by Gauss–Jordan on .
- State and prove the first version of the invertible matrix theorem.
- Factor and by hand, prove that the LU factors are unique, and solve systems with two triangular solves.
- Count the cost of elimination (about flops) and explain why solving with is slower and less reliable.
Chapter 1 — Matrix operations
Terminology
- matrix — a rectangular array of numbers with rows and columns. is the entry in row , column .
- Square matrix — . Its main diagonal is .
- Identity matrix — square, 1 on the main diagonal, 0 elsewhere. for all .
- Zero matrix — all entries 0.
- Equal matrices — same size and the same entry in every position.
Addition and scalar multiplication work entry by entry, exactly as for vectors, and obey the same eight rules. Only matrices of the same size can be added.
The matrix product
If is and is , the product is the matrix with entries
The inner sizes must match: . The example used throughout this chapter:
Four ways to read AB
1. Entry by entry (row times column). is the dot product of row of with column of . For example .
2. By columns. Column of is times column of :
So every column of is a combination of the columns of . Here .
3. By rows. Row of is row of times , so every row of is a combination of the rows of . Here row 1 is . This is the view that explains elimination: row operations combine rows.
4. Columns times rows (sum of outer products). Multiply column of (an matrix) by row of (a matrix). Each such product is a full matrix of rank at most one (Linear Algebra 02), and is their sum:
Here denotes row of . This view reappears in the SVD (Linear Algebra 05), which writes a matrix as a sum of rank-one pieces ordered by importance.
All four give the same numbers because each one computes in position ; they only group the work differently.
Trick: pick the view that matches the question. "Is in the column space?" — columns. "What does a row operation do?" — rows. "What is the rank of ?" — outer products. "Just give me a number" — entries.
Algebraic rules — and what fails
For matrices of compatible sizes:
- (associative), and (distributive), , and .
Proof of associativity. For a vector , , so by the column view. Apply this to each column of : column of is , which is column of .
Three rules from ordinary algebra fail:
- Not commutative. . (Often only one of , is even defined.)
- Zero divisors. With , but .
- No cancellation. does not imply , even when (take , , ).
Common pitfall: , not . The two agree only when .
Chapter 2 — Transpose and special matrices
Transpose
The transpose of an matrix is the matrix with : rows become columns. Rules:
Proof of the last rule. .
The order reverses, just like taking off shoes and socks. The dot product is a matrix product: (a matrix).
Special matrices
| Type | Definition | Useful facts |
|---|---|---|
| Diagonal | for | products and powers act entry by entry on the diagonal |
| Upper triangular | for | product of two upper triangular is upper triangular |
| Lower triangular | for | same for lower; unit lower triangular has 1s on the diagonal |
| Symmetric | and are always symmetric | |
| Permutation | the rows of in some order | reorders the rows of ; |
is symmetric: . For example, with , . This matrix is the heart of least squares (Linear Algebra 05).
Product of lower triangular matrices is lower triangular. If for and for , then in a term can be nonzero only if . When there is no such , so . If both have unit diagonal, .
Permutation matrices. Each row and each column of has exactly one 1. The rows of are orthonormal, so , which means .
Chapter 3 — Block matrices
A matrix can be cut by horizontal and vertical lines into blocks (submatrices). If the column cuts of match the row cuts of , then can be computed block by block, using the same formula as for numbers — but keeping the order of each product:
The four views of Chapter 1 are all special cases: the column view cuts into columns, the row view cuts into rows, and the outer-product view cuts into columns and into rows.
Block elimination and the Schur complement
Let with square and invertible. Eliminating the block is one block row operation — "block row 2 minus times block row 1":
The block is the Schur complement of in . When every block is this is exactly one step of ordinary elimination: . Schur complements appear in statistics (conditional covariance), in optimization and in domain-decomposition solvers.
Watch out: in block formulas every product must keep its order. cannot be rewritten as or .
Chapter 4 — Elementary matrices
An elementary matrix is the result of one row operation on the identity. Multiplying on the left by performs that row operation on (by the row view: row of is row of times ).
Using the system from Linear Algebra 00,
subtracts 3 times row 1 from row 2; subtracts 2 times row 2 from row 3. (No is needed because is already 0.) Then
Every elementary matrix is invertible, and its inverse is elementary of the same type: undo "subtract times row " by "add times row "; undo a swap by the same swap; undo scaling by by scaling by . For example
The product in the "wrong" order is messy
The entry 6 in the first product appears because row 3 is changed using the new row 2, which already contains times row 1; indeed . The inverses, multiplied in the opposite order, do not interact at all: the multipliers and simply drop into place. That clean matrix is , and Chapter 7 is built on it. (The messy product is .)
Chapter 5 — The inverse of a matrix
Definition and uniqueness
A square matrix is invertible (or nonsingular) if there is a matrix with
Then is called the inverse and written . A square matrix without an inverse is singular.
The inverse is unique. If and , then . (This short argument even shows a left inverse and a right inverse must agree.)
Properties. If and are invertible matrices, then
Proof. , and similarly in the other order. For the transpose, take the transpose of : , and similarly .
If is invertible, has exactly one solution for every , namely : it is a solution because , and it is the only one because implies .
The 2 × 2 formula
Proof. Multiply: , and the same holds in the other order. Divide by . If , the same product shows times a matrix gives ; Exercise 6 shows is then singular.
The number is the determinant of the matrix (Linear Algebra 03 defines it for all sizes). For : , so
Gauss–Jordan on [ A | I ]
Why it works. Suppose row operations turn into : . Then is a left inverse of , and (by the invertible matrix theorem below) it is . Applying the same operations to produces . So: row reduce the wide matrix ; if the left half becomes , the right half is . If the left half develops a zero row, is singular.
Worked example. Take the "second difference" matrix
Forward elimination: , then :
The pivots are . Backward elimination: , then :
Divide each row by its pivot:
Two observations that matter later. is symmetric and so is (Exercise 7). And is tridiagonal — mostly zeros — but is completely full. Keep that in mind for Chapter 8.
Chapter 6 — The invertible matrix theorem
Theorem. For a square matrix , the following are equivalent (all true or all false):
- is invertible.
- is row equivalent to .
- has pivot positions.
- has only the trivial solution.
- The columns of are linearly independent.
- has at least one solution for every .
- The columns of span .
- There is an matrix with .
- There is an matrix with .
- is invertible.
- is a product of elementary matrices.
Proof. (1) ⇒ (8) and (1) ⇒ (9): take .
(8) ⇒ (4): if then .
(4) ⇔ (5): this is the definition of independence (Linear Algebra 00, Chapter 8).
(4) ⇒ (3): only the trivial solution means no free variables, so every one of the columns is a pivot column.
(3) ⇒ (2): pivots in an matrix means one pivot in every row and every column, on the diagonal, so the RREF is .
(2) ⇒ (11): gives , a product of elementary matrices.
(11) ⇒ (1): elementary matrices are invertible, and so is any product of invertible matrices.
(9) ⇒ (6): given , the vector satisfies .
(6) ⇔ (7): ranges over all combinations of the columns (Linear Algebra 00).
(6) ⇒ (3): if had fewer than pivots, its echelon form would have a zero last row. Choose with last entry 1; then is inconsistent, and undoing the row operations on gives a with inconsistent, contradicting (6).
(1) ⇔ (10): if is invertible, inverts (Chapter 5); apply this to for the converse.
Every statement is now linked to every other.
Corollary (one-sided is enough). If and are square and , then and . Proof: is statement (9) for , so is invertible; multiply on the left by to get .
Watch out: the corollary needs square matrices. For and , but .
Linear Algebra 02, 03 and 04 add more lines to this list: rank , null space , , and is not an eigenvalue.
Chapter 7 — LU factorization
From elimination to A = LU
Suppose elimination on needs no row exchanges. Then only replacement operations "row minus times row " (with ) are used, and
(written for ; larger is the same). is upper triangular with the pivots on its diagonal. is unit lower triangular, and as Chapter 4 showed, its entries below the diagonal are exactly the multipliers: .
For the running example, the multipliers were , , , so
Multiply it out to check: row 2 of is , and row 3 is .
Solving with L and U
becomes . Put and solve two triangular systems:
- Forward substitution (top to bottom).
- Back substitution (bottom to top).
With : ; gives ; gives . So — exactly the right-hand side that elimination produced in Linear Algebra 00. Then gives , , , as before.
The point: the factorization is done once; each new right-hand side then costs only two cheap triangular solves.
LDU and the symmetric case
Divide each row of by its pivot to get with the diagonal matrix of pivots and unit upper triangular. For the example, and
When is symmetric and has an LU factorization, , so . For a symmetric matrix with all pivots positive this becomes the Cholesky factorization , which costs about half as much as LU.
Uniqueness
Theorem. If is invertible and with unit lower triangular and upper triangular, then and .
Proof. Since is invertible, so are the (and the unit-diagonal always are). From ,
The left side is unit lower triangular (inverses and products of unit lower triangular matrices are unit lower triangular — Chapter 2 and Exercise 5), and the right side is upper triangular. A matrix that is both is diagonal, and its diagonal is all 1s from the left side. So both sides equal , which gives and .
Row exchanges: PA = LU
Elimination breaks down when a zero appears in a pivot position. Example:
The (1,1) entry is 0, so swap rows 1 and 2 first. If all the exchanges are done at the start, they form one permutation matrix , and factors without further trouble:
The multipliers were , (row 3 becomes ), then (row 3 becomes ).
Theorem. For every invertible there is a permutation matrix such that with unit lower triangular and upper triangular with nonzero pivots. An invertible has an LU factorization with no exchanges () exactly when every leading principal submatrix (the top-left block, ) is invertible.
To solve from : , so permute , then do the two triangular solves.
Common pitfall: after factoring , forgetting to apply to . The factorization is of , not of .
Chapter 8 — Cost, and why not to compute the inverse
Counting flops
A flop is one floating-point add, subtract, multiply or divide. At elimination step of an matrix, each of the rows below the pivot needs one division (its multiplier) and a multiply and a subtract for each of the remaining entries. So step costs flops, and in total
Each triangular solve costs about flops. So for : roughly flops to factor, then only about per right-hand side.
Why solving with the inverse is the wrong way
- Speed. Forming costs about flops — roughly three times the LU factorization — and then still costs , the same as the two triangular solves it was supposed to replace. There is nothing to gain even with many right-hand sides, because LU is reusable too.
- Accuracy. Gaussian elimination with partial pivoting is backward stable in practice: the computed exactly solves a system with a very slightly perturbed . Multiplying by a computed inverse does not have this guarantee in general, and its residual is typically larger (Higham, Chapters 9 and 14).
- Structure. A banded or sparse matrix has banded or sparse LU factors (without pivoting, a tridiagonal has bidiagonal and ), but its inverse is usually full — as in Chapter 5 showed. For large sparse problems the inverse may not even fit in memory.
In code this means numpy.linalg.solve(A, b) (which calls LAPACK's LU-based gesv), or scipy.linalg.lu_factor once and lu_solve for each right-hand side — never inv(A) @ b.
Trick: read in a formula as "the solution of ", not as an instruction to invert. The same holds for expressions like (solve with many right-hand sides) and (one solve, then one dot product).
Practice Exercises
Exercise 1 — Order matters
Let and . Compute and . Describe with the row view.
Solution
and , which differ. Row view: is an elementary matrix ("add 2 times row 1 to row 2"), so is with row 2 replaced by .
Exercise 2 — Transpose of a triple product
Prove , and deduce that is symmetric whenever is symmetric.
Solution
. If , then .
Exercise 3 — Inverses
Find the inverse of with the formula, and of by Gauss–Jordan.
Solution
, so the first inverse is .
For the matrix, row reducing gives
Check one entry of : row 3 of times column 1 of is , as it should be.
Exercise 4 — LU by hand
Factor as .
Solution
and give rows and . Then gives row 3 . So
Pivots .
Exercise 5 — Inverse of a unit lower triangular matrix
Show that the inverse of a unit lower triangular matrix is unit lower triangular (this completes the uniqueness proof in Chapter 7).
Solution
A unit lower triangular reduces to using only operations "row minus a multiple of row " with (no swaps, no scaling, since the pivots are already 1). Each such elementary matrix is unit lower triangular, so , the product of these elementary matrices, is unit lower triangular by the Chapter 2 result.
Exercise 6 — A zero pivot that cannot be fixed
Show that if then is singular. Also show that is invertible but has no LU factorization without a row exchange.
Solution
If it is singular. Otherwise and . If were invertible, , a contradiction.
For the second matrix, , so it is invertible. If , the (1,1) entry forces , but then the (2,1) entry is . Its first leading principal submatrix is singular, as the theorem predicts. With the swap, .
Exercise 7 — Symmetric inverse
Prove: if is symmetric and invertible, then is symmetric.
Solution
, using the transpose rule for inverses from Chapter 5 and .
Cheat-sheet
| Topic | Key fact |
|---|---|
| Product size | |
| Four views of | entries, columns , rows, sum of outer products |
| Fails for matrices | , cancellation, "no zero divisors" |
| Transpose | ; is symmetric |
| Block product | same formula as scalars, order kept |
| Schur complement | |
| Elementary matrix | row operation on ; multiply on the left |
| inverse | swap ; negate ; divide by |
| Inverse rules | , |
| Compute | Gauss–Jordan on |
| Square, | then |
| unit lower with multipliers; upper with pivots | |
| Row exchanges | ; solve |
| LU cost | flops; each triangular solve |
| Solve, do not invert | solve(A, b) or lu_factor + lu_solve |
What's next
Linear Algebra 02 steps back from matrices to the structures they act on. It defines a vector space by axioms (so polynomials, functions and matrices count), then subspaces, span, independence, basis and dimension — with a full proof that dimension is well defined (the Steinitz exchange lemma). It then studies the four fundamental subspaces of a matrix, proves that row rank equals column rank, and proves rank–nullity in matrix form.
References
- Gilbert Strang, Introduction to Linear Algebra, 6th edition, Wellesley-Cambridge Press, 2023 — Chapter 2 (elimination matrices, inverses, , transposes and permutations).
- David C. Lay, Steven R. Lay and Judi J. McDonald, Linear Algebra and Its Applications, 6th edition, Pearson, 2021 — Chapter 2 (matrix operations, the invertible matrix theorem, partitioned matrices, LU).
- Lloyd N. Trefethen and David Bau III, Numerical Linear Algebra, SIAM, 1997 — Lectures 20–21 (Gaussian elimination, operation count, pivoting).
- Gene H. Golub and Charles F. Van Loan, Matrix Computations, 4th edition, Johns Hopkins University Press, 2013 — Chapter 3 (LU and its variants).
- Nicholas J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd edition, SIAM, 2002 — Chapter 9 (LU factorization and linear equations) and Chapter 14 (matrix inversion).
- MIT OpenCourseWare, 18.06 Linear Algebra, Spring 2010 (Gilbert Strang) — Lectures 3–5: multiplication and inverses, , transposes and permutations.
Note: this post is in progress. Planned additions: a proof of the leading-principal-submatrix condition for LU without exchanges, a worked partial-pivoting example in three-digit arithmetic, and a short numerical demo comparing
solvewithinv(A) @ bon an ill-conditioned matrix.










