Matrix Operations and Algebra
Learning objectives
- Define matrices and describe their dimensions
- Add matrices and multiply by scalars
- Multiply two matrices of compatible dimensions
- Identify the identity matrix
You already know how to solve a single equation. What about a system of fifty equations in fifty unknowns? The arithmetic is the same; the bookkeeping is what kills you. Mathematicians invented the matrix, a grid of numbers, precisely so the bookkeeping could be done once and for all by a single set of rules. Once you have those rules, the same algebra that handled scales up to systems of any size, to the transformations of geometry, to the data of statistics.
Definition
A matrix is a rectangular array of numbers. An matrix has rows and columns; we denote the entry in row and column by . For example,
A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} is a matrix with .
The first index always names the row; the second names the column. Read row-major (left-to-right, top-to-bottom) and the labels make sense.
Addition and scalar multiplication
Two matrices of the same shape add entry-by-entry: . A scalar multiplies every entry: . Both operations look exactly like componentwise vector arithmetic, because that is what they are.
Matrix multiplication, row meets column
This is the part beginners trip over. If is and is , then is , with
In words: the entry of is the dot product of row of with column of . The "inner dimension" must match, columns of count equal to rows of , or the product is not defined.
- Machine Learning: A neural-network forward pass is a sequence of matrix-vector products followed by nonlinearities; transformer models compute thousands of these per token, and matrix multiplication is the bottleneck GPU vendors race to optimise.
- Computer Graphics: A camera-view transformation in OpenGL is a 4x4 matrix; chaining multiple transforms (model x view x projection) is matrix multiplication, run once per vertex per frame.
- Search Engines: A transition matrix tells you the probability of going from state to state ; multiplying the matrix by itself times gives the -step distribution, Google's original PageRank algorithm is exactly this iteration.
(Hover any cell of the product matrix on the right. Row of lights up green, column of lights up orange, and the dot product that produces that cell appears beneath the grid. Edit any entry; the product updates live.)
What the rules buy you
Matrix multiplication is
- associative: ,
- distributive: ,
- but not commutative: in general.
The failure of commutativity is the single most important fact about matrices. It means matrices are not numbers in disguise, they are operators, and the order in which you apply operations changes the result. Try the Swap button in the widget: compute , then . They almost never agree.
The identity matrix
The identity matrix has on the main diagonal and everywhere else:
I_2 = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}, \qquad I_3 = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}.
It does for matrices what does for numbers: for any compatible . This makes the right base case to test new matrix identities against.
Try it
- Predict first: with A = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix} and B = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}, compute and by hand, which is zero? Enter both matrices in the widget and verify (and note ).
- Predict first: if is the identity matrix, what should equal? Enter B = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} in the widget and verify exactly.
- On paper, multiply \begin{pmatrix} 2 & 3 \\ -1 & 4 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 2 & 5 \end{pmatrix} and verify in the widget.
- Why is it impossible to multiply a matrix by a matrix on the right? Write the inner-dimension condition.
Pause: matrix addition is commutative () but matrix multiplication is not. Why? Look at what each operation does: addition combines two grids of numbers entry-by-entry, multiplication combines operators in sequence.
A trap to watch for
The classic trap is to assume . Even if both products are defined, they almost never agree, and they may have different shapes. Example: is and is . Then is (a scalar) and is (a matrix). The two products are not the same object, they live in different shape-spaces.
A second trap: writing . Wrong. Expand the left side: . The middle terms collapse to only if . For general matrices, you must keep both and separately. The binomial theorem from high school is a special property of commutative arithmetic; it does not survive the move to matrices.
What you now know
You can read a matrix, add two of compatible shape, multiply by a scalar, and compute the product of two matrices via the row-times-column rule. You understand why the order vs matters, and you have the identity matrix to anchor your intuition. The next section attaches a single number, the determinant, to every square matrix and shows what it really means geometrically.
Quick check
Mark section complete →
References
- Lang, S. (1971). Basic Mathematics. Springer. Chapter 17, §1, the original presentation of matrices and the product rule.
- Strang, G. (2016). Introduction to Linear Algebra (5th ed.). Wellesley-Cambridge Press. Chapters 1–2, matrices, columns as vectors, and the row-column dot product worked from scratch.
- Axler, S. (2015). Linear Algebra Done Right (3rd ed.). Springer. §3.C, matrices as representations of linear maps and how the product rule falls out.
- Hoffman, K.; Kunze, R. (1971). Linear Algebra (2nd ed.). Prentice-Hall. Chapter 1: matrix algebra with proofs for every identity used above.