Matrix Operations
Add, scale, and multiply matrices with attention to dimensions.
Linear algebra is the math of vectors and matrices. It lets you handle many equations, or many dimensions, all at the same time instead of one line at a time.
Matrix Operations: the central idea
Matrix operations represent operations on linked systems or linear transformations. Their dimension rules follow from what inputs and outputs can be combined.
Words you need
- Matrix
- A matrix is a rectangular grid of numbers arranged in rows and columns that can store a system of equations, a table of data, or a transformation of space.
- Dimension
- The dimension of a matrix is its number of rows followed by its number of columns, so a 3 by 2 matrix has three rows and two columns, in that order.
- Entry
- An entry is the single number sitting in one row-and-column position, and the entry in row i and column j is written with the subscripts i and j.
- Matrix product
- The matrix product AB is the matrix whose entry in row i and column j is row i of A paired term by term with column j of B and added up.
- Identity matrix
- The identity matrix is the square matrix with 1s down the main diagonal and 0s everywhere else, and multiplying by it leaves any compatible matrix unchanged.
- Transpose
- The transpose of a matrix is the matrix you get by flipping it across its main diagonal, turning every row into a column and every column into a row.
What to know before this lesson
Know rectangular arrays, row-column indexing, scalar arithmetic, and dimensions written as rows by columns.
If one of those prerequisites is uncertain, use the Linear Algebra subject guide to locate the earlier concept before memorizing a procedure.
Matrix operations: a worked example
Every step, with the arithmetic
- Step 1 - Write the two matrices and check sizesA = [1 2 ; 3 4] and B = [5 6 ; 7 8] are both 2 by 2, and the inner 2 matches the inner 2, so AB exists and is 2 by 2
- Step 2 - Row 1 of A times column 1 of B(1)(5) + (2)(7) = 5 + 14 = 19, which is the top-left entry
- Step 3 - Row 1 of A times column 2 of B(1)(6) + (2)(8) = 6 + 16 = 22, which is the top-right entry
- Step 4 - Row 2 of A times column 1 of B(3)(5) + (4)(7) = 15 + 28 = 43, which is the bottom-left entry
- Step 5 - Row 2 of A times column 2 of B(3)(6) + (4)(8) = 18 + 32 = 50, so AB = [19 22 ; 43 50]
- Step 6 - Multiply in the other orderBA top-left is (5)(1) + (6)(3) = 5 + 18 = 23, and finishing gives BA = [23 34 ; 31 46], which is not AB
- Step 7 - Add and scale entry by entryA + B = [1+5 2+6 ; 3+7 4+8] = [6 8 ; 10 12] and 3A = [3 6 ; 9 12]
- Step 8 - Check against the identity matrixA times I = [(1)(1)+(2)(0) (1)(0)+(2)(1) ; (3)(1)+(4)(0) (3)(0)+(4)(1)] = [1 2 ; 3 4], the original A
A $2\times3$ matrix can multiply a $3\times4$ matrix because the inner dimensions match, and the result has the outer dimensions $2\times4$.
Which matrix operations are legal for which sizes, and the size of the answer
| Operation | Size rule | Size of the answer | Example |
|---|---|---|---|
| A + B | Both matrices must be exactly the same size | The same size as the inputs | (2 by 3) + (2 by 3) = 2 by 3 |
| A - B | Both matrices must be exactly the same size | The same size as the inputs | (3 by 1) - (3 by 1) = 3 by 1 |
| kA (scalar multiple) | Any size at all works | The same size as A | 5 times a 2 by 4 stays 2 by 4 |
| AB (product) | Columns of A must equal rows of B | Rows of A by columns of B | (2 by 3)(3 by 4) = 2 by 4 |
| AB (undefined) | 3 columns cannot meet 2 rows | No answer exists | (2 by 3)(2 by 3) is not defined |
| A transpose | Any size at all works | Rows and columns trade places | A 2 by 5 becomes a 5 by 2 |
The step-by-step method for matrix operations
- Write every matrix dimension before choosing addition, multiplication, or another operation.
- For addition match corresponding entries; for multiplication take each row-column dot product.
- Label the result dimension and interpret its entries in the original transformation or system.
How to check your answer
Check one output entry by displaying its complete row-column product and confirm the final matrix has the predicted dimensions.
Multiply back, inspect dimensions, and test the result on a simple vector. Solutions to a system must satisfy every original equation, not merely the reduced matrix.
A mistake that changes the mathematics
Matrix multiplication is generally not commutative. Even when both $AB$ and $BA$ exist, they can represent different transformations.
Explain why the tempting step is invalid, then write the condition or definition that prevents it. This turns the error into a rule you can recognize in a new problem.
Where you will actually use this
Video game graphics
Every rotation, scaling, and move of a 3D model is a matrix, and the graphics card multiplies those matrices together so one product can be applied to millions of points per frame.
Spreadsheet costing
Multiplying a matrix of how many of each part goes into each product by a column of part prices produces a column giving the total material cost of each product in one step.
Image filters
Blurring or sharpening a photo multiplies each little block of pixel values by a small matrix of weights, so the whole effect is described by nine or so numbers.
How matrix operations connects to the rest of linear algebra
- Dot product — Every single entry of a matrix product is a dot product of one row with one column, so matrix multiplication is a whole grid of dot products at once.
- Solving linear systems — Writing a system as Ax = b turns solving equations into undoing a matrix product, which is why the size rules matter before you row-reduce.
- Eigenvalues and eigenvectors — Eigenvectors are the special inputs where the matrix product Av collapses down to plain scalar multiplication.
Try a transfer problem
Multiply a $2\times2$ shear matrix by a rotation matrix in both orders and compare the resulting transformations.
Show the worked answer
Take the shear S = [1 1 ; 0 1] and the quarter-turn rotation R = [0 -1 ; 1 0]. SR = [(1)(0)+(1)(1) (1)(-1)+(1)(0) ; (0)(0)+(1)(1) (0)(-1)+(1)(0)] = [1 -1 ; 1 0]. RS = [(0)(1)+(-1)(0) (0)(1)+(-1)(1) ; (1)(1)+(0)(0) (1)(1)+(0)(1)] = [0 -1 ; 1 1]. The two answers are different matrices, and you can see the difference on a single point. Feed in the vector (1, 0): SR sends it to (1, 1), while RS sends it to (0, 1). The reason is the order of the steps. In SR the rotation happens first and the shear acts on the already-turned picture; in RS the shear happens first and the rotation turns the already-slanted picture. Matrix multiplication records the order of operations, so AB and BA are different jobs even when both products exist.
Work without copying the example. When finished, use the relevant focused calculator or formula reference to check the setup and result, then correct the first line where your reasoning changed. When the method feels reliable, move to linear algebra practice questions.
Questions about matrix operations
Why is AB not the same as BA?
Because a matrix product is a sequence of transformations, and order changes the outcome. With A = [1 2 ; 3 4] and B = [5 6 ; 7 8] you get AB = [19 22 ; 43 50] but BA = [23 34 ; 31 46]. Sometimes only one order is even legal: a 2 by 3 times a 3 by 4 works, while the reverse does not.
Can I multiply a 2 by 3 matrix by another 2 by 3 matrix?
No. The left matrix has 3 columns and the right one has only 2 rows, so there is nothing to pair the third column with and the product is undefined. You could multiply a 2 by 3 by a 3 by 2, which gives a 2 by 2, or transpose the second matrix first to make the inner numbers match.
What does the identity matrix actually do?
It plays the role of the number 1 for matrices. The 2 by 2 identity is [1 0 ; 0 1], and multiplying any 2 by 2 matrix by it in either order returns that matrix unchanged. Geometrically it is the transformation that leaves every point exactly where it was.
Is there such a thing as matrix division?
There is no division symbol for matrices. Instead you multiply by the inverse, written A to the power -1, which satisfies A times its inverse equals the identity. Only square matrices can have inverses, and even then only when the determinant is not zero, so plenty of matrices simply cannot be undone.