Matrix Calculator

Ten matrix operations up to 5×5, with exact fractions

Add, subtract, multiply, raise to a power, transpose, invert and find the determinant, trace or rank of matrices up to 5×5. Accepts fractions, shows exact or decimal results and checks the size rules for you.

Linear AlgebraUpdated October 21, 2026Checked against 8 reference values

Ten matrix operations in one place

This calculator handles the everyday matrix operations for matrices up to 5×5: addition, subtraction, multiplication, scalar multiples, integer powers, the transpose, the determinant, the inverse, the trace and the rank. Pick an operation, size the matrices, and the result updates as you type. Entries can be integers, decimals or fractions such as 2/3, and results can be shown as exact fractions or as decimals.

It suits homework checks, quick transformations in graphics or physics, and chaining several steps together. When you want the full hand working for one operation, the dedicated pages go further: the determinant calculator shows cofactor expansion and row reduction, the inverse calculator shows every Gauss-Jordan row operation, and the RREF calculator reads off solutions of linear systems.

Which sizes each operation accepts

Most errors with matrices are size errors. The calculator checks these rules before computing and tells you which one failed.

OperationRequirementResult
A + B, A − BA and B the same sizeSame size as A
A × BColumns of A = rows of BRows of A × columns of B
k × AAny matrixSame size as A
AⁿSquare A (invertible if n < 0)Same size as A
AᵀAny matrixRows and columns swapped
det(A), tr(A)Square AA single number
A⁻¹Square A with det(A) ≠ 0Same size as A
rank(A)Any matrixA whole number

In a product, entry (i, j) of AB is the dot product of row i of A with column j of B: (AB)ᵢⱼ = Σ aᵢₖbₖⱼ. That is why the inner sizes must match, and why a 2×3 matrix times a 3×2 matrix gives a 2×2 result.

Worked examples

A 2×3 matrix times a 3×2 matrix

With A = [[1, 2, 0], [−1, 3, 2]] and B = [[2, 1], [0, −1], [4, 3]], entry (1, 1) is 1·2 + 2·0 + 0·4 = 2 and entry (2, 2) is (−1)·1 + 3·(−1) + 2·3 = 2. The full product is AB = [[2, −1], [6, 2]].

Inverse of a 3×3 matrix

The matrix [[2, −1, 0], [−1, 2, −1], [0, −1, 2]] has determinant 4, so it is invertible, and Gauss-Jordan elimination gives A⁻¹ = [[3/4, 1/2, 1/4], [1/2, 1, 1/2], [1/4, 1/2, 3/4]]. Every entry is a multiple of 1/4 because the determinant is 4.

A matrix power

Raising [[1, 1], [1, 0]] to the 10th power gives [[89, 55], [55, 34]]. The entries are consecutive Fibonacci numbers, which is a fast way to compute them: repeated squaring needs only a handful of multiplications for large powers.

Rank of a 3×4 matrix

For [[1, 2, 3, 4], [2, 4, 6, 8], [1, 0, 1, 0]], the second row is twice the first, so row reduction leaves 2 nonzero rows. The rank is 2: the rows span a plane, not all of space.

Why the order of multiplication matters

Matrix multiplication is not commutative. For P = [[1, 2], [3, 4]] and Q = [[5, 6], [7, 8]], PQ = [[19, 22], [43, 50]] but QP = [[23, 34], [31, 46]]. Applying one transformation and then another is generally different from applying them the other way round, just as rotating then stretching a shape differs from stretching then rotating.

Other rules carry over from ordinary arithmetic: multiplication is associative, (AB)C = A(BC), and distributes over addition. The transpose and inverse of a product reverse the order: (AB)ᵀ = BᵀAᵀ and (AB)⁻¹ = B⁻¹A⁻¹.

Precision and limits

  • Arithmetic uses double precision. Determinants of integer matrices are computed by cofactor expansion without division, so they come out as exact integers.
  • Fraction display converts each decimal result to the nearest fraction with a denominator up to 1,000 that matches it to about nine significant digits; anything else stays a decimal.
  • A matrix is reported as singular when Gauss-Jordan elimination finds a column with no usable pivot, judged relative to the size of the entries. Nearly singular matrices can have inverses with very large entries that are sensitive to rounding.
  • Powers are limited to exponents from −50 to 50 to keep the entries within floating-point range.

Matrix Calculator: common questions

Is matrix multiplication commutative?

No. AB and BA are usually different, and one of them may not even be defined when the matrices are not square. For example, [[1, 2], [3, 4]] times [[5, 6], [7, 8]] gives [[19, 22], [43, 50]], while the reverse order gives [[23, 34], [31, 46]].

What sizes can be multiplied together?

A product AB exists when the number of columns of A equals the number of rows of B. An m×n matrix times an n×p matrix gives an m×p matrix, so a 2×3 times a 3×4 is a 2×4, while a 2×3 times a 2×3 is undefined.

When does a matrix have an inverse?

A matrix has an inverse only if it is square and its determinant is not zero. Such a matrix is called invertible or nonsingular, and A times its inverse gives the identity matrix.

What does the rank of a matrix tell me?

The rank is the number of independent rows, which always equals the number of independent columns. It is the number of pivots left after row reduction, and it tells you the dimension of the space the matrix maps onto.

Can I enter fractions and get exact answers?

Yes. Type entries such as 3/4 or −5/2, and choose Fractions to see results like 1/3 instead of 0.333333. The calculator works in floating point and converts results back to fractions when they match a fraction with a denominator up to 1,000.

Sources

  • Strang, G., Introduction to Linear Algebra, 5th ed., Wellesley-Cambridge Press, 2016, chapters 2 and 5
  • Lay, D. C., Lay, S. R. and McDonald, J. J., Linear Algebra and Its Applications, 5th ed., Pearson, 2016, chapters 2 and 3

Next steps

More in Linear Algebra