MathsLinear Algebra

Matrix
calculator.

Add, multiply, invert or raise matrices up to 5 by 5, with exact fractions.

How it's worked out

A matrix is a grid of numbers with m rows and n columns, called an m by n matrix. Most mistakes with matrices are size mistakes, so the size rules come first. Each operation only works for certain shapes.

Which sizes each operation accepts
OperationNeedsResult
A + B, A − BSame sizeSame size
A × BColumns of A = rows of BRows of A by columns of B
k × A, AᵀAny sizeSame, or flipped for Aᵀ
Aⁿ, det, traceSquare ASquare, or one number
A⁻¹Square, det not 0Same size

Multiplication uses the row-column rule. Entry i, j of AB is row i of A times column j of B: multiply the pairs and add them up. That is why the inner sizes have to match. An m by n matrix times an n by p matrix gives an m by p matrix.

(AB)ij\displaystyle (AB)_{ij}=ai1b1j+ai2b2j+⋯+ainbnj\displaystyle {}= a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots + a_{in}b_{nj}

The determinant is one number for a square matrix. For a 2 by 2 matrix it is ad minus bc. A larger one is found by expansion along the first row: each entry times the determinant of what is left when you cross out its row and column, with signs that alternate.

det⁡[abcd]\displaystyle \det \begin{bmatrix} a & b \\ c & d \end{bmatrix}=ad−bc\displaystyle {}= ad - bc

The inverse comes from row reduction. Write A next to the identity matrix I, then row-reduce the whole block. When the left side turns into I, the right side is the inverse. If the left side cannot reach I, A has no inverse.

The rank is the number of pivots left after row reduction, which is the number of independent rows. The trace adds the main diagonal. A power multiplies a square matrix by itself; this tool uses repeated squaring, so the 10th power needs only a handful of products.

Worked examples

Maya multiplies a 2 by 3 matrix by a 3 by 2 matrix

Maya has a homework product with two rectangular matrices. A has 3 columns and B has 3 rows, so the product exists, and it is 2 by 2.

[120−132][210−143]\displaystyle \begin{bmatrix} 1 & 2 & 0 \\ -1 & 3 & 2 \end{bmatrix} \begin{bmatrix} 2 & 1 \\ 0 & -1 \\ 4 & 3 \end{bmatrix}=[2−162]\displaystyle {}= \begin{bmatrix} 2 & -1 \\ 6 & 2 \end{bmatrix}

Entry 1, 1 is row 1 of A times column 1 of B: 1 times 2, plus 2 times 0, plus 0 times 4, which is 2. Entry 2, 2 is (−1)(1) + (3)(−1) + (2)(3) = 2.

If she swaps the order, BA is a 3 by 3 matrix instead, with 1 in its top left corner. The two products are not even the same shape.

Open this example in the tool

Leo inverts a 3 by 3 matrix from a physics model

Leo's spring model gives a matrix with 2 on the diagonal and −1 next to it. Its determinant is 4, which is not 0, so the inverse exists.

A−1\displaystyle A^{-1}=[34121412112141234]\displaystyle {}= \begin{bmatrix} \frac{3}{4} & \frac{1}{2} & \frac{1}{4} \\ \frac{1}{2} & 1 & \frac{1}{2} \\ \frac{1}{4} & \frac{1}{2} & \frac{3}{4} \end{bmatrix}

Every entry is a multiple of 1/4 because the determinant is 4. The check multiplies A by this inverse and gets the identity back.

Open this example in the tool

Sam finds Fibonacci numbers with a matrix power

Sam raises the matrix with rows 1, 1 and 1, 0 to the 10th power. The answer holds three Fibonacci numbers in a row: 34, 55 and 89.

[1110]10\displaystyle \begin{bmatrix} 1 & 1 \\ 1 & 0 \end{bmatrix}^{10}=[89555534]\displaystyle {}= \begin{bmatrix} 89 & 55 \\ 55 & 34 \end{bmatrix}

The 5th power gives 3, 5 and 8 in the same places. Each power moves one step along the sequence.

Open this example in the tool

Reading your result

Order matters in a product. With P = [1, 2; 3, 4] and Q = [5, 6; 7, 8], PQ has 19 in its top left corner while QP has 23. Doing one map and then another is not the same as doing them the other way round.

A zero determinant means no inverse. The determinant is 0 exactly when the matrix is not invertible. For [1, 2; 2, 4] it is 0: the second row is twice the first, and the rank is only 1.

Rank counts independent rows. In the 3 by 4 matrix with rows 1, 2, 3, 4 and 2, 4, 6, 8 and 1, 0, 1, 0, the second row is twice the first, so the rank is 2. By the rank theorem, the rank plus the number of free columns equals the number of columns.

Fractions stay exact. The inverse of [1/2, 1/3; 1/4, 1/5] has determinant 1/60, so its inverse has whole numbers: 12, −20, −15 and 30. In the decimal view the same numbers show at the places you pick.

A matrix can act on a point. Rotating the point (3, 1) by 90° is the product of [0, −1; 1, 0] with the column (3, 1), which gives (−1, 3).

Common mistakes

  • Multiplying entry by entry. AB is not the grid of products of matching entries. Each entry of AB uses a whole row of A and a whole column of B.
  • Checking the wrong sizes. For AB, compare the columns of A with the rows of B. Two 2 by 3 matrices can be added but not multiplied.
  • Dividing by a matrix. There is no division. To undo A, multiply by its inverse, and do it on the same side: A⁻¹B and BA⁻¹ are usually different.
  • Trusting a nearly zero determinant. A determinant such as 0.000001 still gives an inverse, but its entries are huge and small typing errors swing them a lot.
  • Rounding the inputs. Typing 0.33 for one third changes the answer. Type 1/3 to keep it exact.

Questions people ask

Each entry of AB pairs rows of A with columns of B, and BA pairs them the other way, so the sums differ. For the two 2 by 2 matrices on this page, PQ starts with 19 and QP with 23. It can also happen that only one order is defined, as with a 2 by 3 and a 3 by 4 matrix.

Sources