Matrix calculator

Free matrix calculator for inverse, determinant, rank, product, LU and Cholesky, with exact fractions and every step of the working shown.

Matrix A
Rows
2
Columns
2

Matrices up to 10 × 10, with at most 24 characters per cell. Exponent from -64 to 64. Diagonalization up to 8 × 8. Free expression: 8 matrices at most. Real numbers only. Exact calculation in fractions, done in your browser.

CALCULATION RECEIPT- / - / -
det(A)5
What you entered
A =
21
13
OperationDeterminant
Size of A2 × 2
PDF: receipt, chart and detailed table.

Step-by-step solution

  1. Starting matrix.

    A =
    21
    13
  2. Column 1: row operations.

    • R₂ ← R₂ − (1/2)·R₁
    21
    05/2
  3. The matrix is now triangular: the determinant is the product of the diagonal, with one sign change per row swap (0).

    det(A) = 2 · (5/2) = 5

What is this tool for?

A matrix is a table of numbers arranged in rows and columns. It can stand for the coefficients of a system of equations, a geometric transformation or a set of measurements. A 2 × 3 matrix has 2 rows and 3 columns, and a matrix is square when those two numbers are equal.

This calculator performs 17 operations on matrices of real numbers, up to 10 × 10. If you are a student, you can check your homework: the step-by-step solution shows every operation, so you can see the step where your working goes wrong.

If you are a researcher, exact fractions spare you rounding errors, you can paste your data instead of retyping it, and you can chain operations by reusing a result as matrix A. The calculation runs in your browser, without sending your numbers to a server, and stays exact in fractions.

How to use it

  1. Choose an operation, then set the size of the matrix with the + and − buttons. For A + B, A × B or a matrix equation, a second grid appears for matrix B.
  2. Type one number per cell: whole numbers, decimals, fractions such as 3/4, or scientific notation such as 1.2e-4. You can also paste a whole table from a spreadsheet, MATLAB or Python.
  3. Read the result on the receipt, then follow the solution line by line just below it. Switch the display to decimals if you need rounded values, and reuse the result as matrix A to chain another operation.

How it is calculated

(A · B)ij = Σk aik · bkj
[A | I] → [I | A−1]
Ri ← Ri − k · Rj
p/q + r/s = (p · s + r · q) / (q · s)

The first line is the product rule: cell (i, j) of A × B comes from multiplying row i of A by column j of B, number by number, then adding the products.

Most other calculations rely on three row operations: swapping two rows, multiplying a row by a non-zero number, and adding a multiple of one row to another, as in the third line of the formula. They change neither the rank nor the solutions of the related system.

For the inverse, write A next to the identity matrix, giving [A | I], then apply Gauss–Jordan elimination: each pivot is brought to 1 and the rest of its column to 0. When the left part has become I, the right part is A⁻¹, because the same operations turned A into I and I into A⁻¹.

Fractions stay exact because the sum, difference, product or quotient of two fractions is still a fraction. The last line of the formula shows this for the sum, and you can practise with the fractions calculator. A decimal is converted as soon as you type it: 0.1 becomes 1/10. There are two exceptions: Cholesky takes square roots, kept in exact form such as √2, and diagonalization computes the eigenvectors numerically, with the ≈ sign, when an eigenvalue is not a fraction.

Worked examples

Inverse of matrix A with rows (2 1) and (1 3)

  1. Matrices are written here row by row. The Example button fills the grid with this matrix A. The determinant is 2 × 3 − 1 × 1 = 5, so the inverse exists. Write [A | I]: (2 1 | 1 0) and (1 3 | 0 1).
  2. Column 1: R₁ ← (1/2)·R₁ brings the pivot to 1, then R₂ ← R₂ − R₁ clears the cell below. This gives (1 1/2 | 1/2 0) and (0 5/2 | −1/2 1).
  3. Column 2: R₂ ← (2/5)·R₂ brings the pivot to 1, then R₁ ← R₁ − (1/2)·R₂ clears the cell above. This gives (1 0 | 3/5 −1/5) and (0 1 | −1/5 2/5).
  4. The left part is the identity, so the right part is the inverse. Check one cell of A × A⁻¹: 2·(3/5) + 1·(−1/5) = 1.

A⁻¹ has rows (3/5 −1/5) and (−1/5 2/5), which is (0.6 −0.2) and (−0.2 0.4) in decimals.

A × B then B × A, where A has rows (1 2) and (3 4), and B has rows (5 6) and (7 8)

  1. Row 1 of A × B: c₁₁ = 1·5 + 2·7 = 19 and c₁₂ = 1·6 + 2·8 = 22.
  2. Row 2 of A × B: c₂₁ = 3·5 + 4·7 = 43 and c₂₂ = 3·6 + 4·8 = 50.
  3. Now reverse the order. Row 1 of B × A: c₁₁ = 5·1 + 6·3 = 23 and c₁₂ = 5·2 + 6·4 = 34.
  4. Row 2 of B × A: c₂₁ = 7·1 + 8·3 = 31 and c₂₂ = 7·2 + 8·4 = 46.
  5. To get B × A in the tool, type B in grid A and A in grid B.

A × B has rows (19 22) and (43 50), while B × A has rows (23 34) and (31 46): order matters.

Each operation explained

Determinant

This single number tells you whether a square matrix can be inverted: it can only if the number is not zero. Calculate it before an inverse, or to find out whether a square system has a unique solution.

The tool reduces the matrix to echelon form, then multiplies the numbers on the diagonal, with one sign change per row swap. For another method, such as Sarrus, open the determinant calculator.

For rows (2 1) and (1 3), R₂ ← R₂ − (1/2)·R₁ gives (2 1) and (0 5/2), so det(A) = 2 · (5/2) = 5.

Inverse

A⁻¹ undoes the effect of A: A × A⁻¹ gives the identity matrix. Use it to isolate a matrix in an equation, since you cannot divide by a matrix.

The tool applies Gauss–Jordan elimination to [A | I], as in the first example. If a pivot is missing, the result is Not invertible.

For rows (1 2) and (2 4), R₂ ← R₂ − 2·R₁ leaves a row of zeros on the left: the rank is 1, not 2, det(A) = 0 and there is no inverse.

Transpose

Aᵀ swaps rows and columns. It appears in least squares and lets you recognize a symmetric matrix, which equals its transpose. Any size is accepted.

Row 1 becomes column 1, row 2 becomes column 2, and so on: cell (i, j) moves to (j, i). The values do not change.

Rows (1 2 3) and (4 5 6) form a 2 × 3 matrix. Its transpose, of size 3 × 2, has rows (1 4), (2 5) and (3 6).

Rank

The rank counts the rows that are truly independent. It reveals redundant data and, with the test for compatibility in the system of equations solver, tells you whether a system has solutions.

The tool reduces the matrix to echelon form and counts the non-zero rows, that is, the pivots. The rank never exceeds the number of rows or the number of columns.

For (1 2 3), (4 5 6), (7 8 9), R₂ ← R₂ − 4·R₁, R₃ ← R₃ − 7·R₁ then R₃ ← R₃ − 2·R₂ give (1 2 3), (0 −3 −6), (0 0 0). The rank is 2.

Multiply by a number

This operation rescales a whole matrix, for example to convert measurements to another unit or to prepare a combination such as 2A − B.

Every cell is multiplied by the number k, which can be a whole number, a decimal or a fraction. The size of the matrix does not change.

With k = 3, rows (1 2) and (3 4) become (3 6) and (9 12).

To the power of

Aⁿ is the product of n copies of a square matrix A. It is used for Markov chains, recurrence relations and counting paths in a graph.

The tool squares repeatedly (A², then A⁴), then multiplies the powers it needs, which reduces the number of products. The exponent runs from −64 to 64: a negative one uses the inverse, and 0 gives the identity matrix.

For rows (1 1) and (1 0) and n = 5: A² gives (2 1) and (1 1), A⁴ gives (5 3) and (3 2), and A⁵ = A · A⁴ gives (8 5) and (5 3), which are Fibonacci numbers.

Row echelon form

This staircase shape is the result of Gaussian elimination. It lets you read the rank and solve a system by working back from the last equation to the first.

Column by column, the tool takes the first non-zero cell as the pivot, swaps rows if needed and clears the cells below it. The pivots are not brought to 1.

(1 2 3), (4 5 6), (7 8 10) becomes (1 2 3), (0 −3 −6), (0 0 1), with 3 pivots.

Reduced row echelon form

This form goes further: each pivot equals 1 and stands alone in its column. You can read the solutions of a system and its free unknowns directly.

The tool applies Gauss–Jordan elimination: it divides each row by its pivot, then clears the other cells of the column, above and below.

(1 2 3), (4 5 6), (7 8 9) becomes (1 0 −1), (0 1 2), (0 0 0), with 2 pivots.

Diagonalization

This operation diagonalizes a square matrix, writing it as A = P · D · P⁻¹ with D diagonal, which makes powers simple. It works up to 8 × 8. For the Jordan form and the SVD, open eigenvalues and eigenvectors.

The tool calculates the characteristic polynomial det(λI − A), whose roots are the eigenvalues, then solves (A − λI)·v = 0 for each one. The eigenvectors form the columns of P. If some are missing, the result is Not diagonalizable.

For rows (2 1) and (1 2): p(λ) = λ² − 4λ + 3 = (λ − 3)(λ − 1). Eigenvalues 3 and 1 have vectors (1 1) and (−1 1). D: (3 0) and (0 1). P: (1 −1) and (1 1). P⁻¹: (1/2 1/2) and (−1/2 1/2).

LU decomposition

It writes A as the product of a lower triangular matrix L and an upper triangular matrix U. It helps when you solve several systems with the same matrix A, since L and U can be reused for each right-hand side.

Gaussian elimination gives U, and each multiplier used goes into L, which has 1s on its diagonal. Rows are swapped only when a pivot is zero, and the result is then written P · A = L · U.

For rows (4 3) and (6 3), R₂ ← R₂ − (3/2)·R₁ gives l₂₁ = 3/2. L: (1 0) and (3/2 1). U: (4 3) and (0 −3/2).

Cholesky decomposition

Reserved for symmetric positive definite matrices, it writes A = L · Lᵀ with L lower triangular. You meet it in statistics, with covariance matrices, and in optimization.

The tool checks that A equals its transpose, then calculates L row by row, with exact fractions and square roots. If a pivot is not strictly positive, it stops and shows Not positive definite.

For (4 12 −16), (12 37 −43), (−16 −43 98), L has rows (2 0 0), (6 1 0), (−8 5 3). Check: 6·6 + 1·1 = 37.

A + B

Addition combines two tables of the same size, for example two series of measurements or the results of two periods.

Each cell of the result is the sum of the two cells in the same position. Order does not matter: A + B and B + A are equal.

If A has rows (1 2) and (3 4), and B has rows (5 6) and (7 8): 1 + 5 = 6, 2 + 6 = 8, 3 + 7 = 10, 4 + 8 = 12. A + B has rows (6 8) and (10 12).

A − B

Subtraction measures the gap between two matrices of the same size, for example between your result and an answer key, or between two data sets.

Each cell of B is taken away from the cell of A in the same position. Here order matters: B − A gives the opposite values.

With the same A and B, 1 − 5, 2 − 6, 3 − 7 and 4 − 8 all equal −4. A − B has rows (−4 −4) and (−4 −4).

A × B

The product chains two transformations, or applies coefficients to data, for example prices to quantities. It also checks an inverse, since A × A⁻¹ must give the identity.

Each cell is a row of A multiplied by a column of B: multiply the numbers in pairs, then add. The second example works through all four cells.

With the same A and B, the first cell is 1·5 + 2·7 = 19, and A × B has rows (19 22) and (43 50).

Solve A·X = B

This operation finds the unknown matrix X such that A·X = B, which amounts to solving one system per column of B. For a single right-hand side and a choice of method, use the system of equations solver.

The tool reduces [A | B] by Gauss–Jordan elimination, and the right part gives X. A row reading 0 = a non-zero value means no matrix X works. A rank below the number of columns of A gives infinitely many matrices X.

With the same A and B, (1 2 | 5 6) and (3 4 | 7 8) become (1 0 | −3 −4) and (0 1 | 4 5). X has rows (−3 −4) and (4 5).

Solve Y + A = B

This operation finds the matrix Y to add to A to get B. It is the simplest matrix equation, and it needs two matrices of the same size.

Isolate Y by subtracting A from both sides, as with numbers: Y = B − A, cell by cell. The solution always exists and is unique.

With the same A and B, 5 − 1, 6 − 2, 7 − 3 and 8 − 4 all equal 4. Y has rows (4 4) and (4 4).

Free expression (A, B, C…)

To calculate with as many matrices as you need, up to 8, in the order you want: B × A, A + B + C + D, (A + B) × C or 2A − B. Each letter in the expression brings up its own grid, in capitals or small letters.

The usual priorities apply: brackets, powers and transposes, products, then sums, from left to right. Each intermediate operation is shown with its matrix. The accepted signs are + − * / and ^. Write A^-1 for the inverse and A^T or A' for the transpose. You can only divide by a number: to divide by B, write A*B^-1.

With A of rows (1 2) and (3 4), and B of rows (5 6) and (7 8): B*A gives rows (23 34) and (31 46), A*B gives (19 22) and (43 50), and A+B gives (6 8) and (10 12).

Names and notation

  • Matrix: from the Latin matrix, related to mater (mother), in the sense of something that gives rise to something else. James Joseph Sylvester brought the word into mathematics in the 19th century. The Arabic مصفوفة comes from صف, a row.
  • A⁻¹: read “A inverse”. A⁻¹ plays for A the role that 1/2 plays for 2. It is not the matrix of the inverses of each cell.
  • Aᵀ: the T stands for transpose. Some French-language textbooks write ᵗA for the same matrix.
  • det(A): short for determinant, a number that determines whether A is invertible. It is also written |A|, even though the result can be negative.
  • Rank: the calculator shows rank(A), and French-language courses often write rg(A). It is the number of pivots.
  • Pivot: the non-zero cell used to clear the other cells of its column. The calculation turns around it as around an axis, which is the meaning of the Arabic word محور.
  • L and U: initials of the English words Lower and Upper, because L only has values on and below the diagonal, and U only on and above it.
  • Gauss: Carl Friedrich Gauss, a German mathematician. The elimination named after him is much older: it already appears in the Chinese work The Nine Chapters on the Mathematical Art.
  • Jordan: in Gauss–Jordan, this is Wilhelm Jordan, a German geodesist, not to be confused with Camille Jordan, the French mathematician who gave his name to the Jordan form.
  • Cholesky: André-Louis Cholesky, a French officer and geodesist, devised this method for surveying calculations. It was published after his death, which occurred during the First World War.
  • R₂ ← R₂ − 3·R₁: “row 2 becomes row 2 minus 3 times row 1”. R stands for row. French and Arabic classes write L₂ ← L₂ − 3·L₁, with L for ligne, and that L₂ has nothing to do with the matrix L of LU.
  • I: the identity matrix, with 1s on the diagonal and 0s elsewhere. A × I = A, just as x × 1 = x for numbers.
  • Echelon: the pivots step down like a staircase. The word comes from the French échelon, the rung of a ladder, and the Arabic درجية comes from درجة, a step.

Tips and limitations

  • Check an inverse: after the calculation, click Use as matrix A, choose A × B and type the original matrix in B. You must get exactly the identity matrix.
  • Type exact values: 1/3 rather than 0.33, which the tool reads as 33/100. A repeating decimal is written 1.3(56).
  • A very long fraction is displayed rounded with the ≈ sign, but Copy the result keeps the exact fraction when the result is a single matrix. A root such as √2 is copied as a decimal.
  • Limits: up to 10 × 10, 8 × 8 for diagonalization, and real numbers only, with no complex numbers and no variables such as x.
  • Results are indicative: for homework or a publication, follow the method you were asked to use and keep an independent check.

Mistakes to avoid

  • Multiplying cell by cell: for the A and B of the example, this would give 5, 12, 21 and 32 instead of (19 22) and (43 50).
  • Inverting each cell: the inverse of the matrix with rows (2 1) and (1 3) does not have cells 1/2, 1, 1 and 1/3, but 3/5, −1/5, −1/5 and 2/5.
  • Forgetting the sign: each row swap changes the sign of the determinant, and multiplying a row by k multiplies the determinant by k.
  • Keeping the same order: the inverse of A × B is B⁻¹ × A⁻¹, and the transpose of A × B is Bᵀ × Aᵀ.

Frequently asked questions

Why fractions instead of decimals?

Every cell is stored as an exact fraction of two whole numbers, so 1/3 stays 1/3 and never turns into 0.3333. Nothing is rounded during the calculation, which is why A times its inverse gives exactly the identity matrix. Choose decimals under Display to read rounded values: only the display changes.

Why does my matrix have no inverse?

A square matrix can only be inverted if its determinant is not zero. When it is 0, at least one row can be built from the others, and elimination produces a row of zeros. The step-by-step solution shows where this happens. You can confirm it with the determinant calculator.

Can I multiply matrices of different sizes?

Yes, if the number of columns of A equals the number of rows of B. The result has as many rows as A and as many columns as B, so a 2 × 3 matrix times a 3 × 4 matrix gives a 2 × 4 matrix. Order matters: A × B and B × A are usually different, and one of them may not even exist.

What happens with a non-square matrix?

Transpose, rank, multiplying by a number, both echelon forms and LU accept rectangular matrices, and so does A·X = B if A and B have the same number of rows. Determinant, inverse, power, diagonalization and Cholesky need a square matrix: otherwise, a message tells you so.

What is the difference between row echelon form and reduced row echelon form?

Row echelon form only requires zeros below the pivots, and it is not unique. Reduced form also requires pivots equal to 1, alone in their columns, and it is unique. For (1 2 3), (4 5 6), (7 8 9), the first gives (1 2 3), (0 −3 −6), (0 0 0) and the second (1 0 −1), (0 1 2), (0 0 0). The rank is 2 in both cases.

When should I use Cholesky rather than LU?

Cholesky only applies if A is symmetric and positive definite, as many covariance matrices are. It then takes about half as many operations as LU. In all other cases, use LU. The matrix with rows (1 2) and (3 4), for example, is not symmetric, so the tool shows Not symmetric.