Matrices and Matrix Operations
A matrix is, at first glance, just a rectangular grid of numbers. But that plain description hides one of the most powerful ideas in all of mathematics: a single matrix can encode an entire transformation — a rule that takes vectors and reshapes them, rotates them, stretches them, or collapses them. Once you see matrices this way, their strange multiplication rule stops looking arbitrary and starts looking inevitable.
In this page we build matrices from the ground up: how to write them, how to add and scale them, and — the crucial part — how and why we multiply them the way we do. Matrix operations are the language behind computer graphics, machine learning, physics simulations, economics, and the solution of linear systems. Master them here and the rest of linear algebra opens up.
Learning Objectives
- Read and write matrix notation, including dimensions, entries, and indexing conventions.
- Perform matrix addition, subtraction, and scalar multiplication fluently.
- Compute matrix products by hand and state exactly when a product is defined.
- Explain why matrix multiplication uses the row-by-column rule rather than entrywise multiplication.
- Recognize the identity matrix and understand what a matrix inverse is and when it exists.
- Connect matrix operations to the composition of linear transformations.
Quick Answer
A matrix is a rectangular array of numbers with rows and columns, written as an matrix. You add or subtract two matrices of the same size entry by entry, and you multiply a matrix by a scalar by scaling every entry. Matrix multiplication is different: to multiply an matrix by an matrix, each entry of the product is the dot product of a row from the first with a column from the second — so the inner dimensions must match, and the result is . The identity matrix acts like the number 1 (it leaves matrices unchanged), and the inverse , when it exists, satisfies . Matrix multiplication is defined this way because it exactly captures the composition of linear transformations.
Where It Came From
Matrices were born from a very practical need: solving systems of linear equations. For centuries, mathematicians manipulated the coefficients of equations directly, and the arrays of numbers that appeared were treated as bookkeeping, not as objects in their own right. Chinese mathematicians in the Nine Chapters on the Mathematical Art (around 200 BCE) already used grid arrangements of coefficients and something very close to Gaussian elimination — but they had no notion of a matrix as a single algebraic thing.
The decisive leap came in the mid-nineteenth century in England. James Joseph Sylvester coined the word matrix in 1850 (from the Latin for "womb," because he saw it as the array from which determinants — minors — are "born"). His friend and collaborator Arthur Cayley then did something revolutionary: in his 1858 Memoir on the Theory of Matrices, he treated matrices as objects you can add, subtract, and — crucially — multiply, with their own algebra. Cayley noticed that when you substitute one linear change of variables into another, the resulting coefficients combine by exactly the row-by-column rule. In other words, he defined matrix multiplication so that it would represent the composition of two linear substitutions. This is the whole reason matrix multiplication looks the way it does; it was reverse-engineered to match how transformations chain together. Cayley also observed that a matrix satisfies its own characteristic equation (the Cayley–Hamilton theorem), cementing matrices as genuine algebraic objects. Later, quantum mechanics (Heisenberg's 1925 "matrix mechanics") and modern computing turned this once-abstract theory into an everyday tool.
Matrix Notation and Basic Structure
A matrix is a rectangular array of numbers arranged in rows and columns. We usually name matrices with capital letters. The matrix
has 2 rows and 3 columns, so we say is a matrix (rows always come first). The individual numbers are called entries or elements. We refer to the entry in row and column as . For the matrix above, (row 1, column 2) and (row 2, column 3).
Some special shapes get their own names:
- A square matrix has the same number of rows and columns ().
- A row vector is a matrix; a column vector is an matrix.
- The main diagonal of a square matrix consists of the entries
Two matrices are equal only if they have the same dimensions and every corresponding entry matches.
Addition, Subtraction, and Scalar Multiplication
These operations are the "easy" ones because they work entry by entry.
To add (or subtract) two matrices, they must be the same size, and you simply combine corresponding entries:
Here , , , and . If the sizes differ, the sum is simply undefined — there is no meaningful way to line the entries up.
Scalar multiplication means multiplying every entry by the same number (a "scalar"):
Each entry is tripled. Subtraction is just adding a scalar multiple of : .
These operations obey the comfortable rules you already expect from ordinary numbers: addition is commutative () and associative, and scalar multiplication distributes over addition ().
Matrix Multiplication: The Row-by-Column Rule
Here the story gets interesting. To multiply matrix by matrix , the number of columns of must equal the number of rows of . If is and is , then the product is . The inner dimensions ( and ) must match and then vanish; the outer dimensions ( and ) survive.
The entry in row , column of is the dot product of row of with column of :
Worked example. Let
Both are , so is . Compute each entry:
- Row 1 · Column 1:
- Row 1 · Column 2:
- Row 2 · Column 1:
- Row 2 · Column 2:
A critical warning: matrix multiplication is not commutative. In general . For the matrices above,
which is completely different from . The order matters, always.
Why Multiplication Is Defined This Way
The row-by-column rule feels bizarre until you know its purpose. A matrix represents a linear transformation — a function that takes an input vector and produces an output vector . For example, applying to the column vector produces a new vector whose components are linear combinations of and .
Now suppose you apply transformation first, then transformation . The combined effect on a vector is . The remarkable fact is that this composition is itself a linear transformation, and the single matrix representing it is exactly the product . Cayley defined multiplication precisely so that "do , then do " equals "do ."
This also explains, at a stroke, two things that puzzle beginners. First, why the inner dimensions must match: the output of must have the right number of components to feed into . Second, why order matters: putting on your socks then your shoes is not the same as shoes then socks — composing transformations depends on which you do first. If multiplication were merely entrywise, it would carry none of this meaning and would be useless for the problems matrices were invented to solve.
The Identity Matrix and the Inverse
Among square matrices, one plays the role that the number 1 plays for ordinary numbers. The identity matrix is the matrix with 1s on the main diagonal and 0s everywhere else:
For any compatible matrix , we have and . The identity represents the transformation that does nothing — it leaves every vector where it is.
The inverse of a square matrix is the matrix that "undoes" it:
Not every matrix has an inverse. A matrix is invertible (or nonsingular) exactly when its determinant is nonzero; if the determinant is zero, the transformation collapses space in a way that cannot be reversed. For a matrix there is a clean formula:
Worked example. Let . The determinant is . Since this is nonzero, is invertible:
Check: . It works.
Real-World Applications
- Computer graphics and games. Every rotation, scaling, and translation of a 3D model is a matrix. Composing them by multiplication lets a GPU transform millions of vertices per frame.
- Machine learning and neural networks. A layer of a neural network multiplies an input vector by a weight matrix; training adjusts those entries. The heaviest computation in deep learning is matrix multiplication.
- Solving linear systems. A system is solved (when possible) by , or more practically by elimination — used in engineering, circuit analysis, and economics.
- Google's PageRank and networks. The link structure of the web is a giant matrix; repeated multiplication reveals which pages are most central.
- Cryptography and error correction. Hill ciphers and coding schemes encode messages by multiplying blocks of data by matrices.
Common Mistakes
Mistake 1: Multiplying matrices entrywise. Students often try to compute by multiplying corresponding entries (like addition). Why it's wrong: that operation (the Hadamard product) exists but is not the standard matrix product and does not represent composition of transformations. Correction: always use the row-by-column dot-product rule.
Mistake 2: Assuming . Because ordinary numbers commute, beginners expect matrices to as well. Why it's wrong: matrix multiplication represents ordered composition, and order changes the result; often one product isn't even defined while the other is. Correction: preserve order carefully and never swap factors.
Mistake 3: Thinking every square matrix has an inverse. Why it's wrong: if the determinant is zero (a singular matrix), the transformation loses information — like projecting 3D onto a plane — and cannot be undone. Correction: always check that (or the determinant more generally) before inverting, and remember non-square matrices never have a two-sided inverse.
Comparison and Connections
Matrix multiplication behaves very differently from ordinary number multiplication, and keeping the differences straight prevents most errors.
| Property | Real numbers | Matrix multiplication |
|---|---|---|
| Commutative | Yes: | No: usually |
| Associative | Yes | Yes: |
| Identity element | The number 1 | The identity matrix |
| Inverse always exists? | Yes, except 0 | No — only if determinant |
| or ? | Yes | No — nonzero matrices can multiply to zero |
Matrix addition, by contrast, behaves just like number addition (commutative and associative). Matrices also connect directly to vectors (which are just single-row or single-column matrices), to determinants (which measure how a matrix scales area or volume and detect invertibility), and to linear transformations (the geometric meaning behind every operation on this page).
Practice Questions
Recall
What are the dimensions of a matrix with 4 rows and 2 columns, and what condition must two matrices satisfy to be added?
Answer: It is a matrix. Two matrices can be added only if they have identical dimensions (same number of rows and same number of columns).
Understanding
If is and is , is defined? What about ? Give the sizes of any defined products.
Answer: is defined because the inner dimensions match (5 = 5), giving a matrix. is not defined, because the inner dimensions (2 and 3) do not match.
Application
Compute where and .
Answer: Row 1: and . Row 2: and . So .
Analysis
Explain, using the idea of transformations, why the inverse of a matrix with determinant 0 cannot exist.
Answer: A determinant of 0 means the transformation squashes space into a lower dimension (for example, mapping a plane onto a line). Multiple distinct inputs then map to the same output, so there is no way to recover the original input uniquely. An inverse would have to reverse the map, but reversing a many-to-one collapse is impossible, so no inverse exists.
FAQ
Is a vector just a special matrix? Yes. A column vector is an matrix and a row vector is a matrix. Everything you learn about matrix operations applies directly to vectors.
Why does the order of multiplication matter so much? Because means "apply first, then ." Composing transformations in a different order generally gives a different result — just as rotating then reflecting differs from reflecting then rotating.
Can I multiply a matrix by another matrix? Not with standard multiplication — the columns of the first (3) do not match the rows of the second (2). You could multiply a by a , though.
What is the difference between the inverse and the transpose? The transpose flips a matrix across its diagonal (rows become columns) and always exists. The inverse undoes the transformation and exists only for invertible square matrices. They are unrelated in general.
Do I always need the inverse to solve ? No, and usually you shouldn't compute it. Gaussian elimination is faster and more numerically stable. The inverse is mainly a conceptual tool and is useful when you must apply the same "undo" to many different vectors.
Quick Revision
- An matrix has rows, columns; entry is row , column .
- Add/subtract: same size only, entry by entry. Scalar multiply: scale every entry.
- Multiply : inner dims must match; (row · column).
- Matrix multiplication is associative but not commutative ( in general).
- Identity : 1s on the diagonal, acts like the number 1: .
- Inverse : satisfies ; exists only when determinant .
- inverse: .
- Multiplication is defined by the row-by-column rule because it represents composition of linear transformations (Cayley, 1858).
Related Topics
Prerequisites
Related Topics
- Vectors and vector operations
- Determinants and their geometric meaning
- Linear transformations
Next Topics
- Systems of linear equations and Gaussian elimination
- Eigenvalues and eigenvectors