Skip to main content
ponderloop

Matrix Calculator

To find the inverse of a matrix, row-reduce A next to the identity matrix until the left half becomes I: for A = [[2, 1], [1, 2]], A⁻¹ = [[2/3, −1/3], [−1/3, 2/3]]. For a 2 × 2 matrix the determinant is ad − bc, so det [[2, 1], [1, 2]] = 3; larger ones are reduced by row operations. Add or subtract matrices of the same size entry by entry: [[1, 2], [3, 4]] + [[5, 6], [7, 8]] = [[6, 8], [10, 12]]. Multiply by taking each row of A times each column of B: [[1, 2], [3, 4]] × [[5, 6], [7, 8]] = [[19, 22], [43, 50]]. The rank is the number of pivots in the row-reduced form: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] has rank 2. This calculator takes matrices up to 6 × 6 as integers, decimals or fractions, keeps every result exact, and lists the row operations.

Updated Runs in your browser: nothing you enter is uploadedHow this tool works

Matrix A
Paste matrix A

Up to 6 × 6. Enter integers (3), decimals (0.75) or fractions (3/4). Pasted values can be separated by spaces, tabs or commas, with rows on separate lines or split by semicolons: [[1,2],[3,4]] works too.

A⁻¹ = [[2/3, −1/3], [−1/3, 2/3]]

Column 1Column 2
Row 12/3−1/3
Row 2−1/32/3
Size
2 × 2
Determinant of A
3
Check
A × A⁻¹ = I

The working, step by step

  1. Write A next to the 2 × 2 identity matrix I, then row-reduce [A | I] until the left half is I. The right half is then A⁻¹.
  2. Start with the matrix.
    Column 1Column 2Column 3Column 4
    Row 12110
    Row 21201
  3. R1 ← R1 ÷ 2 (make the pivot in column 1 equal to 1).
    Column 1Column 2Column 3Column 4
    Row 111/21/20
    Row 21201
  4. R2 ← R2 − R1 (clear the rest of column 1).
    Column 1Column 2Column 3Column 4
    Row 111/21/20
    Row 203/2−1/21
  5. R2 ← R2 ÷ (3/2) (make the pivot in column 2 equal to 1).
    Column 1Column 2Column 3Column 4
    Row 111/21/20
    Row 201−1/32/3
  6. R1 ← R1 − (1/2)·R2 (clear the rest of column 2).
    Column 1Column 2Column 3Column 4
    Row 1102/3−1/3
    Row 201−1/32/3
  7. The left half is now I, so the right half is the inverse A⁻¹.

Worked examples

Each result is worked out by the calculator above; type any of these matrices to see the steps.
OperationMatricesResult
Add: A + BA = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]][[6, 8], [10, 12]]
Multiply: A × BA = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]][[19, 22], [43, 50]]
Multiply (reversed): B × AB = [[5, 6], [7, 8]], A = [[1, 2], [3, 4]][[23, 34], [31, 46]]
Scalar multiply: 1/2 × AA = [[2, 4], [6, 8]][[1, 2], [3, 4]]
Transpose: AᵀA = [[1, 2, 3], [4, 5, 6]][[1, 4], [2, 5], [3, 6]]
Determinant: det(A)A = [[6, 1, 1], [4, −2, 5], [2, 8, 7]][[−306]]
Inverse: A⁻¹A = [[2, 1], [1, 2]][[2/3, −1/3], [−1/3, 2/3]]
Inverse (decimals): A⁻¹A = [[0.5, 0.25], [1.5, 2]][[16/5, −2/5], [−12/5, 4/5]]
Rank: rank(A)A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]][[2]]
RREF: rref(A)A = [[1, 2, 3], [4, 5, 6]][[1, 0, −1], [0, 1, 2]]

Determinant, rank and invertibility of special matrices

A square matrix has an inverse exactly when its determinant is not 0, which is when its rank equals its size.
MatrixEntriesDeterminantRankInvertible
Identity matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]]13Yes
Diagonal matrix[[2, 0, 0], [0, 3, 0], [0, 0, 4]]243Yes
Upper triangular matrix[[1, 2, 3], [0, 4, 5], [0, 0, 6]]243Yes
Rows that are multiples[[1, 2], [2, 4]]01No
Rows in arithmetic progression[[1, 2, 3], [4, 5, 6], [7, 8, 9]]02No
Swap matrix[[0, 1], [1, 0]]−12Yes
Hilbert matrix (fractions)[[1, 1/2, 1/3], [1/2, 1/3, 1/4], [1/3, 1/4, 1/5]]1/21603Yes

Which sizes each operation accepts

Sizes are written rows × columns. The calculator tells you when two matrices do not fit.
OperationNeedsExample
Add or subtractA and B the same size2 × 2 and 2 × 2 give 2 × 2
Multiply A × Bcolumns of A = rows of B2 × 3 times 3 × 4 gives 2 × 4
Scalar multiplyany size2 × 2 gives 2 × 2
Transposeany size2 × 3 gives 3 × 2
Determinant, inversesquare only (n × n)3 × 3 gives 3 × 3 for the inverse
Rank, RREFany size2 × 3 gives 2 × 3 for the RREF

How to find the inverse of a matrix by hand

  1. Check the matrix is square. Only an n × n matrix can have an inverse. For a 2 × 2 matrix, find det = ad − bc: here 3. If the determinant is 0 there is no inverse.
  2. Write A next to the identity matrix. Build the augmented matrix [A | I]. For [[2, 1], [1, 2]] the right half is [[1, 0], [0, 1]].
  3. Row-reduce the left half to the identity. Use three row operations: swap two rows, multiply a row by a non-zero number, or add a multiple of one row to another. Work column by column: make the pivot 1, then clear the rest of its column.
  4. Read the inverse from the right half. When the left half is I, the right half is A⁻¹: [[2/3, −1/3], [−1/3, 2/3]].
  5. Check by multiplying. A × A⁻¹ must give the identity matrix. The calculator confirms it for you: A × A⁻¹ = I.

Frequently asked questions

How do you find the determinant of a matrix?
For a 2 × 2 matrix [[a, b], [c, d]] the determinant is ad − bc: for [[2, 1], [1, 2]] it is 2·2 − 1·1 = 3. For larger matrices, reduce to an upper triangular matrix with row operations that add a multiple of one row to another, which leave the determinant unchanged, and multiply the diagonal. Each row swap flips the sign. For [[6, 1, 1], [4, −2, 5], [2, 8, 7]] the result is −306.
When does a matrix have no inverse?
When it is not square, or when its determinant is 0 (it is “singular”). That happens when one row is a combination of the others, for example [[1, 2], [2, 4]], whose second row is twice the first. Row reduction then runs out of pivots before the left half becomes the identity, and the calculator says so instead of giving an answer.
How do you multiply two matrices?
Each entry of A × B is a row of A times a column of B: multiply matching entries and add. [[1, 2], [3, 4]] × [[5, 6], [7, 8]] = [[19, 22], [43, 50]], because the top-left entry is 1·5 + 2·7 = 19. A must have as many columns as B has rows, and the result has A’s rows and B’s columns: a 2 × 3 matrix times a 3 × 4 matrix is 2 × 4.
Is matrix multiplication commutative?
No. A × B and B × A are usually different, and one of them may not even exist. With the same two matrices, A × B = [[19, 22], [43, 50]] but B × A = [[23, 34], [31, 46]]. Matrix multiplication is associative, though, so (AB)C = A(BC).
What is the rank of a matrix?
The rank is the number of pivots in its reduced row echelon form, which equals the number of linearly independent rows (and of independent columns). The 3 × 3 matrix [[1, 2, 3], [4, 5, 6], [7, 8, 9]] looks full but has rank 2, because its third row is twice the second minus the first. A square matrix is invertible exactly when its rank equals its size.
What is RREF (reduced row echelon form)?
A matrix where each non-zero row starts with a 1 (the pivot), each pivot is to the right of the one above it, and every pivot is the only non-zero entry in its column. [[1, 2, 3], [4, 5, 6]] reduces to [[1, 0, −1], [0, 1, 2]]. Solving a system of linear equations reduces to reading its augmented matrix in RREF, and the calculator lists each row operation that gets there.
Can I enter decimals and fractions?
Yes: integers (3), decimals (0.75) and fractions (3/4) all work in the same matrix, and every result is exact. The inverse of [[0.5, 0.25], [1.5, 2]] is [[16/5, −2/5], [−12/5, 4/5]], not a rounded decimal, and the inverse of the Hilbert matrix [[1, 1/2, 1/3], [1/2, 1/3, 1/4], [1/3, 1/4, 1/5]] comes out as whole numbers: [[9, −36, 30], [−36, 192, −180], [30, −180, 180]].
How do I paste a matrix?
Open “Paste matrix” under the grid, put one row per line with the numbers separated by spaces, tabs or commas, and press the fill button. A selection copied from a spreadsheet works as it is, and so do forms like [[1,2],[3,4]] or 1 2; 3 4. Write fractions without spaces, as 3/4. The grid takes the size of what you pasted, up to 6 × 6.
What does the transpose do?
It turns rows into columns: entry (i, j) moves to (j, i). The 2 × 3 matrix [[1, 2, 3], [4, 5, 6]] becomes the 3 × 2 matrix [[1, 4], [2, 5], [3, 6]]. The determinant of a square matrix is the same as its transpose’s.
What changes the sign of a determinant?
Swapping two rows flips it: the swap matrix [[0, 1], [1, 0]] has determinant −1. Adding a multiple of one row to another changes nothing, and multiplying a row by a number multiplies the determinant by that number. The calculator counts the swaps it makes and applies the sign at the end.

How it works

Every entry you type is read as an exact fraction of two whole numbers (up to 12 digits each): a decimal is its digits over a power of 10, and a fraction a/b is kept as typed, then reduced to lowest terms. Addition, subtraction, scalar multiplication and matrix multiplication use the textbook definitions on those fractions, so nothing is ever rounded. The determinant, rank, RREF and inverse all come from one routine: Gaussian elimination on exact fractions, choosing the first non-zero entry at or below the diagonal as the pivot. The determinant stops at an upper triangular matrix using only “add a multiple of a row” operations, multiplies the diagonal and flips the sign once per row swap; for a 2 × 2 matrix it uses ad − bc directly. The rank counts pivots in the RREF. The inverse row-reduces [A | I] with Gauss-Jordan elimination and then checks that A × A⁻¹ is the identity. Each row operation is shown as it is made, with the matrix after it. Everything runs in your browser and nothing you type is sent anywhere.

Sources

More: Algebra and number theoryAll math & numbersAll toolsHome & DIY calculators