Matrix Calculator

Add, subtract, multiply, transpose, power, determinant and inverse — for any matrices up to 6×6.

Matrix A
×
Matrix B
×

What is a matrix?

A matrix is a rectangular array of numbers arranged in rows and columns. A matrix with m rows and n columns is called an m×n matrix; the entry in row i and column j is written aᵢⱼ. Matrices are the workhorses of linear algebra and show up anywhere a system of linear relationships needs to be represented compactly.

They power computer graphics (every 3D rotation, scaling and projection is a matrix multiplication), statistics (design matrices in regression), physics (states in quantum mechanics, stress tensors in mechanics), economics (input–output models) and machine learning (essentially every modern neural network is a chain of matrix operations).

Matrix calculator, piece by piece

Each card explains one thing this tool actually does with your grid — how it combines two matrices, how it produces a single number (determinant) from a square one, and how it inverts a matrix when that number isn't zero.

Add, subtract, scalar × — the shape-preserving operations

Addition and subtraction work entry by entry, so both matrices must have the same rows and columns. Scalar multiplication is even simpler — every entry is multiplied by the scalar. The output keeps the shape of the input. If your two matrices don't share dimensions, the calculator refuses instead of guessing.

(A ± B)ᵢⱼ = aᵢⱼ ± bᵢⱼ  ·  (kA)ᵢⱼ
= k · aᵢⱼ
1234+5678=681012entry-by-entry — shapes must match
Example
Given
[[1,2],[3,4]] + [[5,6],[7,8]]
Substitute
cell by cell
Answer
[[6,8],[10,12]]

Multiply, power, transpose — how shapes rearrange

Matrix × matrix requires the inner dimensions to match: an m×n times an n×p produces an m×p, and each output entry is the dot product of a row of A with a column of B. Raising a matrix to a positive integer power only works for squares (repeated self-multiply). The transpose just flips rows into columns, so m×n becomes n×m. Multiplication is not commutative — A·B and B·A are usually different even when both exist.

(A·B)ᵢⱼ = Σₖ aᵢₖ bₖⱼ  ·  (Aᵀ)ᵢⱼ
= aⱼᵢ
m × n·n × p=m × p(A·B)ᵢⱼ = Σₖ aᵢₖ · bₖⱼrow of A · column of B (dot product)A·B ≠ B·A in general
Example
Given
[[1,2,3],[4,5,6]] · [[7,8],[9,10],[11,12]]
Substitute
row·col dots
Answer
[[58,64],[139,154]]

Determinant & inverse — the square-matrix helpers

The determinant collapses a square matrix into a single number that says how much the matrix scales area or volume; the sign tells you if it flips orientation. For 2×2 that's simply ad − bc, for larger sizes the calculator uses LU decomposition to stay fast at 5×5 and 6×6. Once det is known the inverse follows: A⁻¹ = (1/det)·adj(A), which the tool computes with Gauss–Jordan. If det(A) = 0 the matrix is singular and the calculator reports that rather than returning nonsense.

2×2: det = ad − bc  ·  A⁻¹
= (1/det) · adj(A)
2×2 det = ad − bcdet [[3,8],[4,6]] = 18 − 32 = −14n≥3 → LU / cofactor expansioninverse = (1/det) · adj(A)det = 0 → singular, no inverseGauss–Jordan used behind the scenes
Example
Given
A = [[4,7],[2,6]]
Substitute
det = 10
swap+negate
Answer
A⁻¹ = [[0.6,−0.7],[−0.2,0.4]]

Common mistakes

  • Trying to add matrices of different sizes. Addition is entry by entry, so the shapes must match exactly.
  • Multiplying matrices in the wrong order. Even when both products are defined, A × B and B × A are usually different.
  • Multiplying two matrices whose inner dimensions do not agree — for example a 2×3 times a 2×2. Check that cols(A) = rows(B).
  • Assuming every square matrix has an inverse. Singular matrices (det = 0) do not; the calculator will flag this.
  • Confusing the transpose with the inverse. Aᵀ is defined for every matrix; A⁻¹ is not.

Features of this calculator

  • Two independent input grids with adjustable rows and columns up to 6×6
  • Fill helpers: all zeros, all ones and random small integers
  • Per-matrix unary tools: transpose, square (A²), determinant and inverse
  • Combined operations: A + B, A − B, A × B and swap A ↔ B
  • Copy any result matrix straight back into A or B for chained work
  • Clear error messages for singular matrices and dimension mismatches

Frequently asked questions

+When can two matrices be added?

Only when they have identical dimensions. Addition is done position by position.

+When can two matrices be multiplied?

When the number of columns of the first matrix matches the number of rows of the second. An m×n times an n×p produces an m×p matrix.

+Which matrices have an inverse?

Only square matrices whose determinant is non-zero. If det(A) = 0 the matrix is singular and there is no inverse.

+Is matrix multiplication commutative?

No. A × B is generally different from B × A, even when both products are defined and the same shape.

+What is the transpose used for?

It is the natural companion of the dot product, appears throughout statistics (Aᵀ A shows up in least squares), and turns row-based data into column-based data.

+Why does the calculator cap dimensions at 6×6?

Above 6×6 the input grid becomes unwieldy on screen. All the underlying algorithms scale much further; the limit is a UX choice.

Related calculators