Matrix Calculator

A free matrix calculator that finds the inverse, determinant, product and more of matrices up to 5×5 with one click.

Matrix A

Matrix B

Operations

A and B
Matrix A
Matrix B

Result

Product A × B

How to use

  • Pick the number of rows and columns (1 to 5) for matrices A and B and type the entries.
  • A + B, A − B and A × B use both matrices; kA, Aᵀ, det(A), A⁻¹, rank(A) and Aⁿ work on one matrix. B has the same buttons, and the chosen operation recalculates whenever you change a value.
  • The scalar k is used for kA and kB, and the whole-number exponent n for Aⁿ and Bⁿ.
  • “Use result as A” copies the result into A so you can keep calculating, and “Swap A and B” exchanges the two matrices.

Matrix multiplication and basic operations

Below, [a b; c d] is the 2×2 matrix with first row a, b and second row c, d. Matrix multiplication follows the row-times-column rule: entry (i, j) of A × B is the sum of the products of row i of A and column j of B, taken entry by entry.

  • Size rule: an m×n matrix times an n×p matrix gives an m×p matrix. The number of columns of the first must equal the number of rows of the second.
  • Example: [1 2 3; 4 5 6] (2×3) × [7 8; 9 10; 11 12] (3×2) = [1·7+2·9+3·11 1·8+2·10+3·12; 4·7+5·9+6·11 4·8+5·10+6·12] = [58 64; 139 154] (2×2)
  • Addition and subtraction work entry by entry, so both matrices must be the same size. kA multiplies every entry by k, and the transpose Aᵀ swaps rows and columns, turning a 2×3 matrix into a 3×2 one.
  • Order matters: A × B and B × A are usually different, and depending on the sizes B × A may not exist at all.

Determinant, inverse and rank by Gaussian elimination

For a 2×2 matrix, det [a b; c d] = ad − bc, and when ad − bc ≠ 0 the inverse is [a b; c d]⁻¹ = 1/(ad − bc) × [d −b; −c a].

Larger matrices are handled with Gaussian elimination with partial pivoting. In each column the entry with the largest absolute value becomes the pivot (swapping rows if needed), and multiples of the pivot row are subtracted from the rows below to create zeros. The determinant is the product of the pivots, with the sign flipped for each row swap.

Example: eliminating [2 1 1; 4 3 3; 8 7 9] by hand without swaps gives R2 − 2R1 = [0 1 1], R3 − 4R1 = [0 3 5] and R3 − 3R2 = [0 0 2], so det = 2 × 1 × 2 = 4. The calculator swaps rows to use 8 as the first pivot, but the determinant is the same.

The inverse comes from applying the same elimination to [A | I] until the left side becomes the identity matrix I; the right side is then A⁻¹ (Gauss–Jordan elimination). The rank is the number of pivots left after elimination, which is the number of linearly independent rows. A pivot smaller than 10⁻¹² times the largest entry counts as 0.

Step-by-step worked example

Using the matrices the page opens with, A = [4 7; 2 6] and B = [1 2; 3 4]:

  • A × B = [4·1+7·3 4·2+7·4; 2·1+6·3 2·2+6·4] = [25 36; 20 28]
  • det(A) = 4 × 6 − 7 × 2 = 24 − 14 = 10
  • Inverse by formula: A⁻¹ = 1/10 × [6 −7; −2 4] = [0.6 −0.7; −0.2 0.4]
  • Check by elimination: starting from [4 7 | 1 0; 2 6 | 0 1], R2 − 0.5R1 → [0 2.5 | −0.5 1], R2 ÷ 2.5 → [0 1 | −0.2 0.4], R1 − 7R2 → [4 0 | 2.4 −2.8], R1 ÷ 4 → [1 0 | 0.6 −0.7]
  • Verify: A × A⁻¹ = [1 0; 0 1]. For powers, A² = A × A = [30 70; 20 50], A⁰ = I and A⁻² = (A⁻¹)² = [0.5 −0.7; −0.2 0.3].

Good to know

  • The determinant, inverse and powers need a square matrix (same number of rows and columns). Transpose, scalar multiple and rank work for any size.
  • A matrix with determinant 0 is singular: it has no inverse, and negative powers such as A⁻¹ or A⁻² can’t be calculated either. Example: [1 2; 2 4] has det = 1 × 4 − 2 × 2 = 0 and rank 1.
  • Empty cells count as 0, and a note appears under the result when that happens. A forgotten entry changes the answer, so check it.
  • Results are shown to 12 significant digits, and tiny rounding leftovers are set to 0, so A × A⁻¹ appears as an exact identity matrix.

Frequently asked questions

How do you find the inverse of a 2×2 matrix?

Swap the two diagonal entries, change the sign of the other two and divide by the determinant: [a b; c d]⁻¹ = 1/(ad − bc) × [d −b; −c a]. For [4 7; 2 6] the determinant is 10, so the inverse is [0.6 −0.7; −0.2 0.4].

Does every matrix have an inverse?

No, a matrix that is not square or whose determinant is 0 (a singular matrix) has no inverse. For example, [1 2; 2 4] has determinant 1 × 4 − 2 × 2 = 0, and the calculator tells you it is singular.

Is A × B the same as B × A?

Usually not. In the example above, A × B = [25 36; 20 28] but B × A = [8 19; 20 45], so the order of matrix multiplication matters.

Which matrices can be multiplied?

The number of columns of the first matrix must equal the number of rows of the second. A 2×3 matrix times a 3×4 matrix works and gives a 2×4 matrix; if the sizes don’t match, the calculator tells you which sizes are needed.

What is the rank of a matrix and how is it found?

It is the largest number of linearly independent rows (or columns), found here as the number of pivots left after Gaussian elimination. For example, [1 2 3; 4 5 6; 7 8 9] has rank 2 because its third row equals 2 × row 2 − row 1, so its determinant is 0.

Can I enter fractions?

No, each cell takes a single number such as −0.25. Enter fractions as decimals, for example 0.5 for 1/2 or 0.333333333333 for 1/3.

What is the largest matrix size?

Up to 5×5. You choose 1 to 5 rows and 1 to 5 columns separately for A and B, so rectangular matrices such as 2×3 or 3×1 work too.