The rules of matrix arithmetic
A matrix is a rectangular grid of numbers. Its size is given as rows × columns, and aij means the entry in row i and column j. Each operation has a rule about which sizes it accepts.
Add or subtract: (A ± B)ij = aij ± bij
Both matrices must be the same size, and matching entries are combined.
Multiply: (AB)ij = ai1b1j + ai2b2j + … + ainbnj
The entry in row i and column j of the product comes from row i of A and column j of B: multiply them pair by pair and add. A must have as many columns (n) as B has rows. An m × n matrix times an n × p matrix gives an m × p matrix.
Determinant of a 2 × 2 matrix with rows (a, b) and (c, d): det = ad − bc
Inverse of the same matrix: A⁻¹ = 1 ÷ (ad − bc) × the matrix with rows (d, −b) and (−c, a)
Only square matrices have a determinant, and an inverse exists only when the determinant is not zero. For larger matrices the determinant is found by expanding along the first row: each entry is multiplied by the determinant of the smaller matrix left when its row and column are removed, with signs alternating +, −, +, −.
Transpose: (Aᵀ)ij = aji Trace: tr(A) = a11 + a22 + … + ann
The transpose swaps rows with columns. The trace is the sum of the main diagonal of a square matrix. The rank is the number of rows that are not all zeros once the matrix has been row-reduced, which counts how many rows carry independent information.
Worked example
Take A with rows (4, 7) and (2, 6), and B with rows (1, 2) and (3, 4).
- Multiply A × B. Top left: 4 × 1 + 7 × 3 = 25. Top right: 4 × 2 + 7 × 4 = 36. Bottom left: 2 × 1 + 6 × 3 = 20. Bottom right: 2 × 2 + 6 × 4 = 28. The product has rows (25, 36) and (20, 28).
- Determinant of A. 4 × 6 − 7 × 2 = 24 − 14 = 10.
- Inverse of A. Swap the diagonal entries, change the sign of the other two, and divide by 10: rows (6/10, −7/10) and (−2/10, 4/10), which simplify to (3/5, −7/10) and (−1/5, 2/5).
- Check. A × A⁻¹ should be the identity matrix. Top left: 4 × 3/5 + 7 × (−1/5) = 12/5 − 7/5 = 1. Top right: 4 × (−7/10) + 7 × 2/5 = −28/10 + 28/10 = 0.
For a 3 × 3 determinant, take rows (1, 2, 3), (0, 1, 4) and (5, 6, 0). Expanding along the first row gives 1 × (1 × 0 − 4 × 6) − 2 × (0 × 0 − 4 × 5) + 3 × (0 × 6 − 1 × 5) = −24 + 40 − 15 = 1. Because the determinant is 1, the inverse has whole-number entries: rows (−24, 18, 5), (20, −15, −4) and (−5, 4, 1).
Order matters in multiplication
With ordinary numbers, 3 × 5 and 5 × 3 are the same. With matrices they usually are not. Using the same A and B, B × A has rows (8, 19) and (20, 45), nothing like A × B. If the sizes differ, one order may not even be allowed: a 2 × 3 matrix times a 3 × 1 matrix works, but the reverse does not. When the calculator reports a size mismatch for A × B, check whether you meant B × A.
Two facts do survive. The determinant of a product is the product of the determinants: det(A) = 10, det(B) = −2, and det(AB) = 25 × 28 − 36 × 20 = −20. And the trace is the same either way round: 25 + 28 = 53 and 8 + 45 = 53.
Singular matrices and why fractions matter
A matrix with a determinant of zero is called singular and has no inverse. It happens when one row can be built from the others. For rows (2, 0, 1), (1, 3, 2) and (1, 1, 1) the determinant is 2 × (3 − 2) − 0 + 1 × (1 − 3) = 0, and the rank is 2, not 3, because the first row equals three times the third row minus the second.
Software that works in decimals can miss this. The matrix with rows (0.1, 0.7) and (0.3, 2.1) is singular, since the second row is three times the first. In ordinary floating-point arithmetic, though, 0.1 × 2.1 − 0.7 × 0.3 comes out as roughly 0.00000000000000003 instead of 0, and a program that trusts it will return an “inverse” full of numbers around 1016. This calculator converts every entry to a fraction first, gets exactly 0, and tells you the matrix cannot be inverted.
Using the results
- Solving equations. The pair 4x + 7y = 5 and 2x + 6y = 4 is A times the column (x, y) equal to the column (5, 4). Multiplying A⁻¹ by (5, 4) gives x = 1/5 and y = 3/5. Enter the right-hand side as a 2 × 1 matrix B and multiply.
- Scaling. Multiplying every entry of an n × n matrix by k multiplies the determinant by kn, not by k. Doubling A above turns its determinant from 10 into 40.
- Reading the determinant. Its size is the factor by which the matrix scales areas (2 × 2) or volumes (3 × 3), and a negative sign means the orientation is flipped.
- Reading the rank. A square matrix has an inverse exactly when its rank equals its size. A lower rank tells you how many equations in a system are genuinely independent.