What Is a Matrix? Grids of Numbers That Rotate, Solve and Rank
By the BrainSnail editorial team. How these articles are written and checked, and how to tell us when one is wrong.
A rotation of a picture on a screen, the solution of a set of equations with a thousand unknowns, the ranking of every page on the web and the guts of a language model are all the same operation, a grid of numbers multiplied by a list of numbers to produce another list. The grid is a matrix, the word is Latin for womb and was chosen by James Joseph Sylvester in 1850 for a thing out of which other things are born, and the arithmetic of matrices, worked out by Arthur Cayley in 1858, is what a graphics card does several trillion times a second.
What it is
A matrix is a rectangular array of numbers with a set number of rows and columns, a 2 by 3 matrix having two rows and three columns, and on its own it is only a table. It becomes a machine when it is multiplied by a vector, a column of numbers: each row of the matrix is laid alongside the vector, the matching entries are multiplied and the products added, and the result is one entry of a new vector. A 2 by 2 matrix therefore turns any point in the plane into another point, and the matrix is a way of writing down the whole transformation at once. The identity matrix, with ones down the diagonal and zeros elsewhere, leaves every vector unchanged; every other matrix stretches, squashes, rotates, reflects or shears the plane, and the entries say how.
The rules
Matrices add entry by entry and are scaled entry by entry, like vectors, and the operation that makes them useful is multiplication of one by another, which is the composition of the two transformations: doing the second matrix's transformation after the first is the same as applying their product. The product is computed row against column, and it has properties that surprise:
- •Order matters: A times B is not in general B times A, since rotating and then reflecting is not the same as reflecting and then rotating
- •Inverse: a matrix that undoes another exists only if the first lost no information, which is when its determinant is not zero; a matrix that flattens the plane to a line cannot be undone
- •Determinant: a single number computed from the entries that gives the factor by which the matrix scales area or volume, and whose sign says whether it flips orientation
- •Transpose: the matrix flipped across its diagonal, rows becoming columns
- •Eigenvectors: the directions a matrix stretches without turning, and eigenvalues, the amounts by which it stretches them, which reveal what a transformation fundamentally does
Solving equations
The oldest use is the reason the subject exists. A system of linear equations, three unknowns in three equations, is a matrix of coefficients times a vector of unknowns equalling a vector of constants, and solving it is finding the inverse of the matrix or, more practically, reducing it by the systematic elimination that the Chinese Nine Chapters described around 200 BC and that Gauss made a method in 1810. Every engineering analysis, from the stresses in a bridge to the flow of heat through an engine, ends in a system of thousands or millions of linear equations, and the algorithms for solving them fast, exploiting matrices that are mostly zeros, are among the most used programs in existence; weather forecasts, oil reservoirs and the structure of aircraft are all matrices being solved.
Graphics, ranking and learning
A 3D scene is a list of points, and moving the camera, rotating an object or projecting the scene onto a flat screen is a matrix multiplied by every point, which is why graphics hardware is built to multiply small matrices by enormous numbers of vectors at once; a 4 by 4 matrix, with an extra coordinate that lets translation be included, is the unit of all of it. Google's original PageRank treated the web as a matrix whose entry in row i and column j was the fraction of page j's links that pointed to page i, and the ranking of every page was the eigenvector of that matrix, found by repeated multiplication. A neural network is a chain of matrices, each layer a matrix that transforms the vector from the layer before, with the entries adjusted by training until the chain maps a picture to a label or a sentence to its continuation, and the trillions of parameters in a large model are the entries of its matrices. The graphics card that was built for games turned out to be the right machine for that too.
Beyond the grid
Matrices appeared in physics in 1925 when Werner Heisenberg found that the quantities of quantum mechanics obeyed a multiplication in which order mattered, and Max Born recognised the rules as Cayley's; the measurements of a quantum system are eigenvalues of matrices, and the fact that position times momentum is not momentum times position is the uncertainty principle in one line. A matrix is also a graph, a network of connections written as a table, a Markov chain of probabilities, a rotation of the Earth, a shuffle of a deck and the mixing of an image; the subject called linear algebra is the study of what all of these have in common, and it is the most useful mathematics that most people are never taught.
A rotation worked through by hand
Take the matrix with 0 and minus 1 in its top row and 1 and 0 in its bottom row. Multiply it by the point (1, 0): the top row gives 0 times 1 plus minus 1 times 0, which is 0, and the bottom row gives 1 times 1 plus 0 times 0, which is 1. The point has moved to (0, 1). Every point is turned a quarter turn anticlockwise about the origin, and the whole rotation is captured by those four numbers. Its determinant is 0 times 0 minus minus 1 times 1, which is 1, telling you areas are unchanged.
Now take a stretch, the matrix with 2 and 0 on top and 0 and 1 below, which doubles every horizontal distance. Rotate the point (1, 0) and then stretch: it goes to (0, 1) and stays there. Stretch first and then rotate: it goes to (2, 0) and then to (0, 2). The same two operations in a different order land the point in different places, which is what non-commuting multiplication looks like in practice. Working a few examples like this by hand is the quickest way to make the rules feel like geometry rather than bookkeeping.
How much work a multiplication takes
Multiplying two matrices row against column is expensive. Each entry of the product needs one multiplication for every position along a row, so two matrices of 1,000 rows and 1,000 columns need 1,000 multiplications for each of their million entries, a billion in all. Double the size and the work rises eightfold, because the count grows with the cube of the size. For a long time it was assumed that nothing better was possible, since every entry seems to need every multiplication. Then in 1969 the German mathematician Volker Strassen showed that two 2 by 2 matrices could be multiplied using seven multiplications instead of eight.
Saving one multiplication in eight sounds trivial, but a large matrix can be split into four blocks, each a smaller matrix, and the same trick applied inside every block, so the savings compound and the work grows roughly with the size raised to the power 2.81 rather than 3. Mathematicians have pushed the theoretical limit down ever since, to about 2.37, though those methods are so complicated that they are slower in practice for any matrix a real computer handles. In 2022 an artificial intelligence system from DeepMind found new shortcuts for some small block sizes, a sign that even this old problem is not finished.
An entire economy in one table
In the 1930s and 1940s the economist Wassily Leontief used matrices to describe how the industries of a whole economy depend on each other. In his input-output tables, each row and column stands for an industry, and each entry records how much one industry buys from another to make its own products, so steel goes into cars, electricity into steel, and so on.
With matrix algebra, economists can then work out how much every industry must produce to meet a given final demand, and how a change in one sector ripples through the rest. Leontief received the Nobel Prize in economics in 1973 for this work, and input-output analysis is still used by governments to plan, to estimate the effects of new projects and to trace things like carbon emissions through supply chains.
The takeaway
A matrix is a grid of numbers that transforms vectors when multiplied by them, and the product of two matrices is the composition of their transformations, with order mattering, an inverse only where nothing was flattened, a determinant that measures scaling and eigenvectors that show what the matrix really does. It solves systems of equations for engineering and weather, moves every point in computer graphics, ranks the web through an eigenvector, forms the layers of a neural network and writes the laws of quantum mechanics.