Calculatormatics

Last updated: April 2026 · Reviewed by Calculatormatics Editorial Team

Matrix Calculator — Addition, Multiplication, Transpose, Determinant & Inverse (2×2 to 4×4)

A matrix is a rectangular array of numbers arranged in rows and columns. Matrix algebra underpins computer graphics (3D rotation and scaling), physics (quantum mechanics, stress tensors), engineering (finite element analysis), and machine learning (neural networks, PCA, linear regression). This calculator handles the six most common matrix operations: addition, subtraction, multiplication, transpose, determinant, and inverse — for square matrices from 2×2 up to 4×4. Enter your values, choose an operation, and the result appears instantly with calculation steps shown below. Unlike most online tools, this calculator shows the step-by-step arithmetic so you can follow and verify each computation yourself.

Matrix A

Matrix B

A × B:

1922
4350
Matrix multiplication: C[i][j] = sum over k of A[i][k] × B[k][j]

C[1][1] = 1×5 + 2×7 = 19
C[1][2] = 1×6 + 2×8 = 22
C[2][1] = 3×5 + 4×7 = 43
C[2][2] = 3×6 + 4×8 = 50

Matrix Basics

A matrix is described by its dimensions: m rows × n columns. An individual element is written as aij, where i is the row index and j is the column index (both starting at 1). For example, in a 3×3 matrix A, the element in row 2 column 3 is a23.

Not all operations are defined for all pairs of matrices. The rules are:

Because this calculator uses the same size for A and B, addition, subtraction, and multiplication are always dimension-compatible.

Matrix Multiplication

Matrix multiplication is the most conceptually demanding of the six operations. The element C[i][j] of the result is computed as the dot product of row i of A with column j of B:

c_ij = sum over k of (a_ik × b_kj)
     = a_i1×b_1j + a_i2×b_2j + ... + a_in×b_nj

A key property: matrix multiplication is not commutative. That is, A × B and B × A generally produce different results (and sometimes one is defined while the other is not). This is fundamentally different from multiplying ordinary numbers, where 3 × 5 = 5 × 3 always. In matrix algebra, the order matters.

Matrix multiplication is, however, associative: (A × B) × C = A × (B × C). And it is distributive over addition: A × (B + C) = A×B + A×C.

Worked Example: 2×2 Multiplication

Let A = [[1, 2], [3, 4]] and B = [[5, 6], [7, 8]]. We compute each element of C = A × B:

A = | 1  2 |    B = | 5  6 |
    | 3  4 |        | 7  8 |

c[1][1] = 1×5 + 2×7 = 5 + 14  = 19
c[1][2] = 1×6 + 2×8 = 6 + 16  = 22
c[2][1] = 3×5 + 4×7 = 15 + 28 = 43
c[2][2] = 3×6 + 4×8 = 18 + 32 = 50

Result C = A × B = | 19  22 |
                   | 43  50 |

Notice that B × A would give a different result (check: B×A[1][1] = 5×1 + 6×3 = 23 ≠ 19), confirming that matrix multiplication is not commutative.

The Transpose

The transpose of a matrix A, written AT, is formed by swapping rows and columns. Formally: AT[i][j] = A[j][i]. An m×n matrix becomes n×m after transposition.

If A = | 1  2  3 |
       | 4  5  6 |

Then A^T = | 1  4 |
           | 2  5 |
           | 3  6 |

The transpose has important special cases:

The Determinant

The determinant is a single number derived from a square matrix that encodes geometric and algebraic information about the transformation the matrix represents. Geometrically, |det(A)| is the scale factor by which the transformation changes volumes (or areas in 2D). If det(A) is negative, the transformation also reverses orientation (like a reflection).

For a 2×2 matrix:

A = | a  b |
    | c  d |

det(A) = a×d − b×c

For a 3×3 matrix, the determinant is computed by cofactor expansion along the first row:

det(A) = a₁₁×(a₂₂×a₃₃ − a₂₃×a₃₂)
       − a₁₂×(a₂₁×a₃₃ − a₂₃×a₃₁)
       + a₁₃×(a₂₁×a₃₂ − a₂₂×a₃₁)

When det(A) = 0, the matrix is singular: it collapses space (one or more rows are linearly dependent), and no inverse exists. When det(A) = 1, the transformation preserves volume exactly. Rotation matrices always have det = 1; reflection matrices have det = -1.

The Inverse

The inverse of a square matrix A, written A-1, is the matrix that "undoes" the transformation: A × A-1 = A-1 × A = I (the identity matrix). An inverse exists if and only if det(A) ≠ 0 (the matrix is non-singular).

For a 2×2 matrix, the inverse is given by the adjugate formula:

A = | a  b |          A⁻¹ = (1/det) × |  d  −b |
    | c  d |                           | −c   a |

where det = a×d − b×c

For 3×3 and 4×4 matrices, the process involves computing the cofactor matrix (replacing each element with the signed determinant of the submatrix obtained by deleting its row and column), transposing it to form the adjugate, and dividing by the determinant. This calculator uses the mathjs library, which implements numerically stable algorithms for all sizes up to 4×4.

The inverse is fundamental to solving linear systems: if Ax = b (where b is a vector of known values and x is the unknown), then x = A-1b. This is used everywhere from electrical circuit analysis to structural engineering to machine learning regression.

Applications

Matrix operations appear in a surprisingly wide range of fields:

Frequently Asked Questions

Why does matrix multiplication require the inner dimensions to match?

When you compute C = A × B, each element C[i][j] is the dot product of row i of A with column j of B. To take that dot product, row i of A and column j of B must have the same number of elements. That count — the number of columns in A and the number of rows in B — is called the "inner dimension." If A is m×n and B is n×p, the inner dimensions are both n, so multiplication is defined. This calculator uses square matrices (same size for A and B), so the inner dimensions always match.

What does it mean for a matrix to be singular?

A square matrix is singular when its determinant equals zero. Geometrically, this means the transformation represented by the matrix collapses space by at least one dimension — points, lines, or planes get "squashed" together, and you cannot reverse the operation. Algebraically, the rows (or columns) are linearly dependent, meaning at least one row can be expressed as a combination of others. A singular matrix has no inverse.

Is matrix multiplication commutative?

No. In general, A × B ≠ B × A. For example, A = [[1,2],[3,4]] and B = [[5,6],[7,8]] gives A×B = [[19,22],[43,50]] but B×A = [[23,34],[31,46]]. This is one of the most important properties distinguishing matrix algebra from ordinary number arithmetic. There are special cases where A×B = B×A (such as when one matrix is the identity), but this is the exception rather than the rule.

What is the identity matrix?

The identity matrix I is the matrix equivalent of the number 1. It has 1s on the main diagonal (top-left to bottom-right) and 0s everywhere else. Multiplying any matrix A by the identity gives A back unchanged: A × I = I × A = A. The identity is also the result of multiplying a matrix by its inverse: A × A⁻¹ = I. For a 2×2 matrix, I = [[1,0],[0,1]].

How do I verify a matrix inverse is correct?

Multiply the original matrix A by its computed inverse A⁻¹. If the inverse is correct, the result should be the identity matrix I (1s on the diagonal, 0s elsewhere). Due to floating-point arithmetic, very small numbers like 1.5e-15 may appear instead of exact 0s — these are numerical rounding errors and can be treated as zero. Our calculator rounds results to 10 decimal places to minimise this effect.

Why does this calculator only support up to 4×4?

For most practical problems in physics, engineering, and introductory linear algebra, 2×2, 3×3, and 4×4 matrices are sufficient. Computer graphics transformations (rotation, scaling, translation in 3D) use 4×4 matrices. Beyond 4×4, determinant and inverse calculations become unwieldy to display step-by-step. For larger matrices, dedicated software such as MATLAB, NumPy (Python), or R is more appropriate.