Matrix calculator

Determinant, inverse, rank and RREF of a matrix up to 6 × 6 with every row operation shown, plus transpose, product and sum, in exact fractions.

Drafted with AI writing toolsUpdated Checked examples: 8

One row per line (or rows separated by ;), entries separated by spaces or commas; fractions like 1/2 work
Try
Result
[0, 0, 1; −2, 1, 3; 3, −1, −5]
Result: [0, 0, 1; −2, 1, 3; 3, −1, −5]
det A
−1
rank A
3
trace A
5

A is invertible (det A = −1); the inverse undoes A, so A × A⁻¹ is the identity matrix.

A⁻¹

001−2133−1−5
A⁻¹ Rows: 3
Col 1Col 2Col 3
001
−213
3−1−5
How it's calculated S
  1. Write [A | I]

    [211100132010100001]\left[\begin{array}{ccc|ccc}2 & 1 & 1 & 1 & 0 & 0 \\ 1 & 3 & 2 & 0 & 1 & 0 \\ 1 & 0 & 0 & 0 & 0 & 1\end{array}\right]
  2. Column 1

    R1↔R2, R2←R2−2R1, R3←R3−R1  ⟶  [1320100−5−31−200−3−20−11]R_{1} \leftrightarrow R_{2},\ R_{2} \leftarrow R_{2} - 2R_{1},\ R_{3} \leftarrow R_{3} - R_{1} \;\longrightarrow\; \left[\begin{array}{ccc|ccc}1 & 3 & 2 & 0 & 1 & 0 \\ 0 & -5 & -3 & 1 & -2 & 0 \\ 0 & -3 & -2 & 0 & -1 & 1\end{array}\right]
  3. Column 2

    R2←−15 R2, R1←R1−3R2, R3←R3+3R2  ⟶  [101535−1500135−1525000−15−35151]R_{2} \leftarrow -\frac{1}{5}\,R_{2},\ R_{1} \leftarrow R_{1} - 3R_{2},\ R_{3} \leftarrow R_{3} + 3R_{2} \;\longrightarrow\; \left[\begin{array}{ccc|ccc}1 & 0 & \frac{1}{5} & \frac{3}{5} & -\frac{1}{5} & 0 \\ 0 & 1 & \frac{3}{5} & -\frac{1}{5} & \frac{2}{5} & 0 \\ 0 & 0 & -\frac{1}{5} & -\frac{3}{5} & \frac{1}{5} & 1\end{array}\right]
  4. Column 3

    R3←−5 R3, R1←R1−15R3, R2←R2−35R3  ⟶  [100001010−2130013−1−5]R_{3} \leftarrow -5\,R_{3},\ R_{1} \leftarrow R_{1} - \frac{1}{5}R_{3},\ R_{2} \leftarrow R_{2} - \frac{3}{5}R_{3} \;\longrightarrow\; \left[\begin{array}{ccc|ccc}1 & 0 & 0 & 0 & 0 & 1 \\ 0 & 1 & 0 & -2 & 1 & 3 \\ 0 & 0 & 1 & 3 & -1 & -5\end{array}\right]
  5. The right half is the inverse

    A−1=[001−2133−1−5]A^{-1} = \left[\begin{array}{ccc}0 & 0 & 1 \\ -2 & 1 & 3 \\ 3 & -1 & -5\end{array}\right]

    Check: A × A⁻¹ = I.

About the matrix calculator

The calculator works on matrices up to 6 × 6 in exact fractions. The inverse and the reduced row echelon form come from Gauss–Jordan elimination: [A | I] is row-reduced until the left half is the identity, and the right half is then A⁻¹. The determinant is the product of the pivots from forward elimination, negated once for each row swap; the rank is the number of pivots; and a product has entries (AB)ᵢⱼ = Σₖ aᵢₖbₖⱼ.

Linear algebra courses, 3D graphics transforms and systems of equations are the usual uses. The default matrix [2 1 1; 1 3 2; 1 0 0] has determinant −1, so it is invertible, and its inverse [0 0 1; −2 1 3; 3 −1 −5] has whole-number entries.

Type one row per line, with entries separated by spaces or commas; fractions such as 1/2 stay exact. A matrix with determinant 0 is singular: it has no inverse, and its rank is below its size.

How to find the inverse of a 2×2 matrix

For A = [a b; c d], swap a and d, change the signs of b and c, and divide by the determinant: A⁻¹ = [d −b; −c a] ÷ (ad − bc). For [4 7; 2 6], ad − bc = 24 − 14 = 10, so A⁻¹ = [6 −7; −2 4] ÷ 10 = [3/5 −7/10; −1/5 2/5]. It works only when ad − bc ≠ 0.

Check the answer by multiplying: A × A⁻¹ gives the identity matrix [1 0; 0 1]. A matrix with determinant 0, such as [1 2; 2 4], whose second row is twice the first, has no inverse.

How to multiply matrices

Each entry of AB is a row of A times a column of B, summed: (AB)ᵢⱼ = Σₖ aᵢₖbₖⱼ. For [1 2; 3 4] × [5 6; 7 8], the top-left entry is 1 × 5 + 2 × 7 = 19, and the full product is [19 22; 43 50].

A must have as many columns as B has rows, and the product has A's rows and B's columns: a 2 × 3 matrix times a 3 × 2 matrix gives a 2 × 2 matrix. Multiplying them the other way round gives a 3 × 3 matrix instead.

Order matters even for square matrices. Swapping the two matrices above gives BA = [23 34; 31 46]. Addition and subtraction work entry by entry and need two matrices of the same shape.

OperationABResult
multiply[1, 2; 3, 4][5, 6; 7, 8][19, 22; 43, 50]
multiply[5, 6; 7, 8][1, 2; 3, 4][23, 34; 31, 46]
inverse[4, 7; 2, 6]—[3/5, −7/10; −1/5, 2/5]
transpose[1, 2, 3; 4, 5, 6]—[1, 4; 2, 5; 3, 6]
subtract[1/2, 1; 0, 2][1/3, 1; 1, 0][1/6, 0; −1, 2]
add[1, 2; 3, 4][5, 6; 7, 8][6, 8; 10, 12]

The transpose swaps rows and columns, so a 2 × 3 matrix becomes 3 × 2. It is a different operation from the inverse. Fractions stay exact, as in 1/2 − 1/3 = 1/6.

Inverse and determinant of a 3×3 or larger matrix

Gauss–Jordan elimination is the standard method. Write A beside the identity, [A | I], and apply row operations until the left half becomes I; the right half is then A⁻¹. If a column has no pivot, the determinant is 0 and there is no inverse.

The determinant is the product of the pivots from forward elimination, with the sign flipped once for each row swap. For A = [2 1 1; 1 3 2; 1 0 0], det A = −1 and A⁻¹ = [0 0 1; −2 1 3; 3 −1 −5].

MIT's determinant and inverse lesson shows how determinants, cofactors and inverses connect.

How to find the cofactor matrix

To find the cofactor Cᵢⱼ, delete row i and column j, take the determinant of the smaller matrix that remains (the minor), and multiply by (−1)ⁱ⁺ʲ. The signs form a checkerboard that starts with + in the top-left corner. For A = [2 1 1; 1 3 2; 1 0 0]:

Position (i,j)MinorMinor determinantSignCofactor
1,1[3, 2; 0, 0]0+0
1,2[1, 2; 1, 0]−2−2
1,3[1, 3; 1, 0]−3+−3
2,1[1, 1; 0, 0]0−0
2,2[2, 1; 1, 0]−1+−1
2,3[2, 1; 1, 0]−1−1
3,1[1, 1; 3, 2]−1+−1
3,2[2, 1; 1, 2]3−−3
3,3[2, 1; 1, 3]5+5

The cofactor matrix is [0 2 −3; 0 −1 1; −1 −3 5]. Its transpose is the adjugate, and dividing the adjugate by det A = −1 gives the inverse [0 0 1; −2 1 3; 3 −1 −5].

Cofactors also give the determinant: multiply each entry of one row by its cofactor and add. Along row 1, det A = 2 × 0 + 1 × 2 + 1 × (−3) = −1.

Trace, rank and reduced row echelon form

The trace is the sum of a square matrix's diagonal entries: 2 + 3 + 0 = 5 for the matrix above.

The rank is the number of independent rows, which always equals the number of independent columns. [1 2 3; 2 4 6; 1 1 1] has rank 2, because its second row is twice the first.

Reduced row echelon form (RREF) turns each pivot into 1 with zeros above and below it. Put a linear system's constants in the last column, and the RREF of that augmented matrix shows whether the system has a solution:

  • One solution: x + y = 3 and x − y = 1 give [1 1 3; 1 −1 1], which reduces to [1 0 2; 0 1 1]. So x = 2 and y = 1.
  • Infinitely many: [1 1 3; 2 2 6] reduces to [1 1 3; 0 0 0]. The second equation repeats the first, leaving x + y = 3.
  • No solution: [1 1 3; 1 1 5] reduces to [1 1 0; 0 0 1]. The row [0 0 1] means 0 = 1: x + y cannot equal both 3 and 5.

Common mistakes

  • Multiplying entry by entry. Matrix multiplication pairs rows with columns. The entry-wise product is a different operation, the Hadamard product.
  • Reversing the order. AB and BA usually differ, and one of them may not exist.
  • Forgetting to transpose the cofactor matrix. The inverse uses the adjugate, so the untransposed cofactor matrix divided by the determinant is wrong.
  • Rounding fractions early. Typing 0.33 for 1/3 changes every result that depends on it; type the fraction itself.

Matrix input format

  • Put one row per line, or separate rows with semicolons; separate entries with spaces or commas.
  • Fractions such as 1/2 stay exact. Irrational entries such as π are carried as 50-digit decimals.
  • Matrices can be up to 6 × 6.
  • There is no cofactor operation. Enter each minor as Matrix A, take its determinant, and attach the checkerboard sign yourself.

To solve equations with named unknowns, use the system of linear equations solver. For dot and cross products, use the vector calculator.

Worked examples

Inverse of the default 3 × 3

Calculate
Inverse of A
Matrix A
2 1 1 1 3 2 1 0 0
Result
[0, 0, 1; −2, 1, 3; 3, −1, −5]
det A
-1

Checked against: Fractions Gauss–Jordan on [A | I]; det by cofactor expansion = −1

Inverse of [4 7; 2 6]

Calculate
Inverse of A
Matrix A
4 7 2 6
Result
[3/5, −7/10; −1/5, 2/5]
det A
10

Checked against: (1/(ad − bc))·[d −b; −c a] = (1/10)·[6 −7; −2 4]

Determinant of the default 3 × 3

Calculate
Determinant of A
Matrix A
2 1 1 1 3 2 1 0 0
Result
−1
det A
-1
trace A
5

Checked against: Cofactor expansion: 2·0 − 1·(0 − 2) + 1·(0 − 3) = −1

Rank of a singular matrix (edge case)

Calculate
Rank of A
Matrix A
1 2 3 2 4 6 1 1 1
Result
2
rank A
2
det A
0

Checked against: Row 2 = 2 × row 1; with exact fractions RREF has 2 pivots

Questions

How do you find the inverse of a matrix?

Write A next to the identity matrix, [A | I], and apply row operations until the left half becomes I; the right half is then A⁻¹. A 2 × 2 matrix [a b; c d] has a shortcut: A⁻¹ = (1/(ad − bc)) × [d −b; −c a]. For [4 7; 2 6], ad − bc = 24 − 14 = 10, so A⁻¹ = [3/5 −7/10; −1/5 2/5].

How do you calculate the determinant of a 3 × 3 matrix?

Expand along a row or column, multiplying each entry by the determinant of its 2 × 2 minor with alternating signs. For [2 1 1; 1 3 2; 1 0 0], the bottom row is quickest because two of its entries are 0: det = 1 × (1 × 2 − 1 × 3) = −1. For larger matrices row reduction reaches the same answer with far fewer operations.

When does a matrix have no inverse?

When its determinant is 0, which happens exactly when one row or column is a combination of the others. In [1 2 3; 2 4 6; 1 1 1], row 2 is twice row 1, so the rank is 2 rather than 3 and the determinant is 0. Such a matrix is called singular, and a system Ax = b built on it has either no solution or infinitely many.

How do you multiply two matrices?

Each entry of AB is a row of A times a column of B, summed: (AB)ᵢⱼ = Σₖ aᵢₖbₖⱼ. For [1 2; 3 4] × [5 6; 7 8] the top-left entry is 1 × 5 + 2 × 7 = 19, and the product is [19 22; 43 50]. A needs as many columns as B has rows, and order matters: here BA = [23 34; 31 46].

What is reduced row echelon form?

A matrix is in reduced row echelon form (RREF) when each non-zero row starts with a 1, that leading 1 is the only non-zero entry in its column, the leading 1s step right going down, and zero rows sit at the bottom. Every matrix has exactly one RREF, and its number of leading 1s is the rank. For an augmented matrix it reads off the solution: [1 0 0 −8; 0 1 0 1; 0 0 1 −2] means x = −8, y = 1, z = −2.

About this calculator

A−1: [A∣I]⟶[I∣A−1](AB)ij=∑kaikbkj\begin{gathered} A^{-1}:\ [A \mid I] \longrightarrow [I \mid A^{-1}] \\[10pt] (AB)_{ij} = \sum_k a_{ik} b_{kj} \end{gathered}

Sources

  1. Wikipedia — Gaussian elimination (row reduction and the RREF example)
  2. Wolfram MathWorld — Matrix Inverse
  3. G. Strang, Introduction to Linear Algebra (5th ed.), chapters 2–3

Checked against references

This calculator includes 8 worked examples with independently sourced answers. They run in the test suite, and you can run them here too.

Put this calculator on your site

Paste this where you want the calculator to appear. It is free to use, it stays in step with corrections made here, and the credit line below it links back so your readers can find the full version.

Height
Preview the embed

Keep the credit line. It is the only condition, and it is what keeps these calculators free.