Linear algebra is the language that lets you handle many numbers and many equations at once, and almost all of it is built from two objects: the vector and the matrix. This article works up from a single ordered list of numbers to the point where you can solve a whole system of equations three different ways and know which to reach for. Everything connects, so it pays to read it in order.
Vectors
A vector is simply an ordered list of numbers called its components, and the word ordered is doing real work. Swapping two components produces a different vector, so position carries meaning. Vectors can be written as a column or as a row, and the number of components is the vector’s dimension.
Two vectors are equal only when they share the same dimension and agree in every corresponding component. That is why the two three-dimensional vectors below are not equal: they have the same entries but in a different order, and the first components already disagree.
Operating on vectors
Three operations apply to vectors. Transposition flips a column into a row or back again, scalar multiplication scales every entry by the same number, and addition or subtraction combines two vectors entry by entry. The last two require both vectors to have the same dimension, and transposing twice returns the original vector. Take the row vectors below as an example.
Scaling the first by three multiplies each entry by three.
Adding and subtracting works component by component.
The dot product
The dot product takes two vectors of the same dimension, multiplies their corresponding entries, and sums the results. Crucially, the output is a single scalar rather than a vector.
This is more than an abstraction. In economics it computes total revenue as the sum of price times quantity across a bundle of goods. If prices in pence are 40, 50, and 30 for apples, bananas, and oranges, and the quantities sold are 5, 3, and 4, the dot product gives the total takings.
That is 470 pence, or four pounds seventy, from selling the bundle.
Matrices
A matrix is a rectangular array of numbers arranged in rows and columns, and its dimension is written as the number of rows by the number of columns. When those two counts are equal it is a square matrix. The entry in row i and column j is written with a double subscript, and two matrices of the same dimension are equal exactly when every corresponding entry matches. Matrices are a natural way to organise real data. Suppose a company has three stores each stocking four products, computers, printers, monitors, and modems. Putting stores in rows and products in columns gives a single tidy object.
This is a three by four matrix, and the entry in row two, column three, which is 155, tells you the second store holds 155 monitors.
Operating on matrices
Matrices support the same three operations as vectors, now applied across the whole grid. Transposition swaps rows and columns, turning an m by n matrix into an n by m one, and it has no dimension requirement. Scalar multiplication scales every entry. Addition and subtraction work entry by entry and require the two matrices to share a dimension. Take the matrix below.
Its transpose turns each row into a column.
A linear combination simply scales and then combines. With the second matrix B below, the combination 2A minus 3B is computed by scaling each, then subtracting entry by entry.
Matrix multiplication
Matrix multiplication is where things get less obvious, and the rule that governs it is about shapes. The product of A and B exists only when the number of columns of A equals the number of rows of B, and the result has as many rows as A and as many columns as B.
Each entry of the product is the dot product of a row of A with a column of B.
Consider a two by two matrix times a two by three matrix. The shared inner dimension of two means the product exists and is two by three.
Computing each entry as a row-times-column dot product gives the result.
The order matters enormously. Here the reverse product does not even exist, because B has three columns while A has only two rows, and more generally, even when both products exist they are usually different. Matrix multiplication is not commutative.
Determinants
Every square matrix has an associated scalar called its determinant, and it turns out to govern whether the matrix can be inverted and whether a linear system has a unique solution. For a two by two matrix there is a direct formula.
For larger matrices you use cofactor expansion along any row or column, and a useful fact is that the answer is identical whichever row or column you pick. That freedom is worth exploiting: always expand along the row or column with the most zeros, since each zero entry kills a whole term. Take the three by three matrix below and expand along its second row, which contains a zero.
The leading zero contributes nothing, leaving two cofactors to compute.
Combining them through the expansion gives the determinant.
Minors and cofactors
Those building blocks deserve their own definition, because they power both determinants of large matrices and the inverse. The minor of an entry is the determinant of the smaller matrix left after deleting that entry’s row and column. The cofactor is the minor with a sign attached.
The sign factor alternates in a checkerboard pattern, plus in the top-left corner.
For the same three by three matrix, deleting row one and column three leaves a two by two block whose determinant is the minor, and since one plus three is even the cofactor keeps the same sign.
The identity and the inverse
The identity matrix is the matrix world’s version of the number one. It has ones down the main diagonal and zeros elsewhere, and multiplying any compatible matrix by it leaves that matrix unchanged.
The inverse of a square matrix is the matrix that multiplies it back to the identity, and it exists if and only if the determinant is nonzero.
For a two by two matrix the inverse has a memorable closed form: swap the diagonal entries, negate the off-diagonal ones, and divide by the determinant.
For three by three and larger, the inverse is the transpose of the cofactor matrix divided by the determinant.
Take the matrix below as a worked case.
Expanding along the first row gives a determinant of minus two, which is nonzero, so the inverse exists. Computing all nine cofactors, transposing them, and dividing by the determinant produces the inverse.
Writing a system in matrix form
The payoff for all this machinery is that any system of linear equations collapses into a single compact statement. A system of m equations in n unknowns becomes a coefficient matrix times a vector of unknowns equalling a vector of right-hand sides.
For instance the three equations 2x plus 3y minus z equals 5, x minus y plus 2z equals 1, and 4x plus y plus z equals 7 pack into the following form, where each row of the coefficient matrix is one equation.
From here there are three standard ways to solve, and the rest of the article is each one in turn.
Gaussian elimination
The most general method is to reduce the augmented matrix, the coefficient matrix with the right-hand side attached as an extra column, to echelon form using row operations that never change the solution set. There are exactly three legal operations: swap two rows, multiply a row by a nonzero number, and add a multiple of one row to another. The goal is a staircase of leading ones, each one further right than the one above, after which back substitution reads off the answer. Consider the system 2x plus 2y plus 3z equals minus one, 3x plus 5y plus 4z equals one, and x plus 2y plus z equals one. Its augmented matrix is below.
Swapping the first and third rows puts a convenient leading one at the top, then subtracting multiples of that row clears the first column below it, and continuing the process down the columns reaches a clean echelon form.
Back substitution now works upward. The bottom row gives z equals minus one, the middle row then gives y equals one, and the top row gives x equals zero. Gaussian elimination always works, and it is the method to use when you do not yet know whether the determinant is nonzero, since it also reveals when a system has no solution or infinitely many.
Solving with the inverse
When the determinant is nonzero the system has a unique solution, and you can reach it directly by left-multiplying both sides by the inverse.
Reusing the three by three matrix whose inverse we already found, with a right-hand side of 2, 4, 6, the multiplication gives the solution in one step.
This method shines when you already have the inverse, or when you must solve the same coefficient matrix against many different right-hand sides.
Cramer’s rule
The third method gives each unknown directly as a ratio of two determinants, with no full inverse required. Form a new matrix by replacing the i-th column of the coefficient matrix with the right-hand side, take its determinant, and divide by the determinant of the original.
For the same system, whose coefficient determinant is minus two, replacing each column in turn and computing the three determinants gives minus six, minus two, and two.
The answer matches the inverse method exactly, which is the reassuring sign that everything is consistent. Cramer’s rule is most attractive for small systems, or when you only need the value of a single variable rather than all of them.
Prepared a few exercises for you here: https://datalad.co.uk/matrices-and-linear-equations-exercises-with-worked-solutions/
Choosing a method
The three approaches are not rivals so much as tools for different situations. Gaussian elimination is the workhorse that always applies and is the only one of the three that gracefully handles systems with no solution or infinitely many, so reach for it whenever you are unsure about the determinant. The inverse method is efficient when the determinant is nonzero and you either already have the inverse or need to solve against several right-hand sides. Cramer’s rule is the quick route for small systems or for extracting one specific unknown. Underneath all three sits a single fact worth holding onto: a square system has a unique solution precisely when the determinant of its coefficient matrix is nonzero, and when that determinant is zero the matrix has no inverse and the system has either no solution or infinitely many.
See you soon.
[…] Matrices and Systems of Linear Equations […]
[…] Matrices and Systems of Linear Equations […]