Matrix Calculator — Add, Multiply & Invert
Perform matrix addition, subtraction, multiplication, transposition, and find the determinant and inverse for matrices up to 4×4. Step-by-step working shown for all operations.
Quick Presets
Operation
Matrix A Size
What Is the Matrix Calculator — Add, Multiply & Invert?
This matrix calculator handles six fundamental linear algebra operations on matrices up to 4×4 in size. Enter values directly into the grid cells, choose an operation, and get instant results with step-by-step working for determinant, inverse, and multiplication.
- ›Six operations — addition, subtraction, multiplication, transpose, determinant, and inverse, all in one tool without switching pages.
- ›Up to 4×4 matrices — rows and columns independently adjustable from 1 to 4, with Matrix B having its own size selector for multiply.
- ›Step-by-step determinant — for 2×2 shows ad−bc substitution; for 3×3 shows cofactor expansion term by term.
- ›Adjugate inverse method — the inverse panel shows each cofactor, the transposed adjugate, and the final (1/det)·adj(A) division.
- ›Real-time dimension validation — for multiplication, the tool shows whether dimensions are compatible and explains why not if they aren't.
- ›Quick presets — identity matrices, rotation matrices, and worked examples load instantly so you can see the format before entering your own data.
Formula
Matrix Addition & Subtraction
(A ± B)ᵢⱼ = Aᵢⱼ ± Bᵢⱼ (requires same dimensions m×n)
Matrix Multiplication
(AB)ᵢⱼ = Σₖ Aᵢₖ · Bₖⱼ (A is m×n, B must be n×p → result is m×p)
Transpose
(Aᵀ)ᵢⱼ = Aⱼᵢ (rows become columns, m×n → n×m)
Determinant (2×2)
det(A) = ad − bc for A = [[a,b],[c,d]]
Determinant (3×3) — Cofactor Expansion along Row 1
det(A) = a₁₁·M₁₁ − a₁₂·M₁₂ + a₁₃·M₁₃
where Mᵢⱼ = determinant of the 2×2 submatrix with row i, col j removed
Matrix Inverse
A⁻¹ = adj(A) / det(A) (exists only when det(A) ≠ 0)
For 2×2: A⁻¹ = (1/det) × [[d,−b],[−c,a]]
| Symbol | Name | Description |
|---|---|---|
| A | Matrix A | First matrix (m×n) — the primary operand |
| B | Matrix B | Second matrix (p×q) — used in add, subtract, multiply |
| Aᵀ | Transpose | Matrix with rows and columns swapped — shape n×m |
| det(A) | Determinant | Scalar value for square matrices; zero means non-invertible |
| A⁻¹ | Inverse | Exists only when det(A) ≠ 0; satisfies A · A⁻¹ = I |
Dimension Compatibility Rules
Addition/Subtraction: A (m×n) ± B (m×n) → result (m×n) [same size]
Multiplication: A (m×n) × B (n×p) → result (m×p) [inner dims match]
Transpose: A (m×n)ᵀ → result (n×m)
Determinant: A must be square (n×n)
Inverse: A must be square and det(A) ≠ 0
How to Use
- 1Choose an operation: Click one of the six operation tabs: Add, Subtract, Multiply, Transpose, Determinant, or Inverse.
- 2Set matrix dimensions: Use the Rows/Cols dropdowns to choose the size of Matrix A (1–4 each). For Multiply, set Matrix B size too — the inner dimensions must match.
- 3Enter matrix values: Click each cell and type a number. Tab moves to the next cell. All cells accept decimals and negative numbers.
- 4Try a preset: Click Identity 2×2, Identity 3×3, Rotation 45°, or Example to load a pre-filled matrix instantly.
- 5Press Enter or click Calculate: Results appear immediately. For determinant and inverse, expand the step-by-step panel to see the full working.
- 6Read the result: The result matrix appears in the same grid style. For determinant, a large number is shown. For inverse, fraction notation is used when values are clean.
Example Calculation
Example 1: 2×2 Matrix Multiplication
A = [[1,2],[3,4]] B = [[5,6],[7,8]]
C = A × B:
C₁₁ = 1×5 + 2×7 = 5 + 14 = 19
C₁₂ = 1×6 + 2×8 = 6 + 16 = 22
C₂₁ = 3×5 + 4×7 = 15 + 28 = 43
C₂₂ = 3×6 + 4×8 = 18 + 32 = 50
Result: [[19, 22], [43, 50]]
Example 2: 2×2 Determinant
A = [[2, 3], [1, 4]]
det(A) = ad − bc
= 2×4 − 3×1
= 8 − 3
det(A) = 5
Note on Matrix Inverse
Since det(A) = 5 ≠ 0, the inverse exists. For A = [[2,3],[1,4]]: A⁻¹ = (1/5) × [[4,−3],[−1,2]] = [[0.8, −0.6], [−0.2, 0.4]]. Verify: A × A⁻¹ = I₂ (the 2×2 identity matrix).
Understanding Matrix — Add, Multiply & Invert
Matrix Operations Explained
A matrix is a rectangular array of numbers arranged in rows and columns. Matrices are one of the most powerful tools in mathematics, used everywhere from rendering 3D graphics to solving systems of equations. Each operation transforms matrices in a specific, well-defined way.
- ›Addition and subtraction — element-by-element operations requiring both matrices to have identical dimensions. The sum A+B has (A+B)ᵢⱼ = Aᵢⱼ + Bᵢⱼ.
- ›Multiplication — the most important operation. AB requires A to be m×n and B to be n×p. The result is m×p, and each entry is a dot product of a row of A with a column of B.
- ›Transpose — flips a matrix along its main diagonal. A row vector becomes a column vector and vice versa. Used heavily in statistics (covariance matrices) and optimization.
- ›Determinant — a single scalar that encodes the scaling factor of the linear transformation described by the matrix. Non-zero determinant means the transformation is invertible.
- ›Inverse — the matrix A⁻¹ such that A·A⁻¹ = I. Found via the adjugate: A⁻¹ = adj(A)/det(A). Only square matrices with non-zero determinants have inverses.
When Matrix Multiplication is Defined
Unlike addition, matrix multiplication is not always possible. The number of columns in A must equal the number of rows in B. If A is m×n and B is p×q, the product AB is defined only when n = p. The result has dimensions m×q.
Critically, matrix multiplication is not commutative: AB ≠ BA in general. Even when both products are defined, the results can differ. This non-commutativity is why order matters in transformations — rotating then scaling gives a different result than scaling then rotating.
The dimension rule in one line
(m × n) × (n × p) = (m × p)
The two bold n values must match. The result drops those inner dimensions.
The Determinant Geometrically
The determinant of a 2×2 matrix measures the signed area of the parallelogram spanned by its row (or column) vectors. For a 3×3 matrix it is the signed volume of the parallelepiped. Key interpretations:
- ›det = 0 — the matrix is singular (non-invertible). Its rows are linearly dependent, meaning the transformation collapses space down to a lower dimension.
- ›|det| > 1 — the transformation stretches space by this factor.
- ›|det| < 1 — the transformation compresses space.
- ›det < 0 — the transformation includes a reflection (orientation reversed).
- ›det = 1 — the transformation preserves area/volume (e.g. pure rotation).
Finding the Matrix Inverse
The most systematic method for small matrices is the adjugate (classical adjoint) method:
- ›Compute the matrix of cofactors Cᵢⱼ = (−1)^(i+j) × Mᵢⱼ, where Mᵢⱼ is the minor (determinant of the submatrix with row i, col j deleted).
- ›Transpose the cofactor matrix to get the adjugate: adj(A) = Cᵀ.
- ›Divide by the determinant: A⁻¹ = adj(A) / det(A).
- ›Verify by checking A × A⁻¹ = I (the identity matrix).
For larger matrices (5×5 and above), Gaussian elimination (row reduction) is more efficient, but for 2×2–4×4 the adjugate method gives clean step-by-step working.
Common Applications of Matrices
| Field | How Matrices Are Used |
|---|---|
| Computer graphics | 4×4 transformation matrices handle translation, rotation, scaling, and perspective projection in 3D rendering. |
| Economics | Input-output models (Leontief) use matrix equations to model interdependencies between sectors. |
| Physics / engineering | Systems of equations in circuit analysis, structural FEM, and quantum mechanics are represented as matrix equations. |
| Statistics | Covariance matrices, regression coefficients, and PCA all rely on matrix operations and eigendecomposition. |
| Cryptography | Hill cipher encrypts messages by multiplying plaintext vectors with a key matrix mod 26. |
Frequently Asked Questions
Is matrix multiplication commutative?
No — matrix multiplication is not commutative in general.
- ›For non-square matrices, AB and BA may not even be the same size.
- ›For square matrices of the same size, AB and BA are both defined but usually different.
- ›Special cases where AB = BA: diagonal matrices, scalar multiples of the identity, and a matrix multiplied by its own powers.
- ›This non-commutativity is exactly why transformation order matters in 3D graphics and robotics.
What does a determinant of zero mean?
A zero determinant means the matrix is singular — it cannot be inverted.
- ›The rows (or columns) are linearly dependent — at least one is a linear combination of the others.
- ›The matrix represents a transformation that collapses space to a lower dimension.
- ›The system of equations Ax = b either has no solution or infinitely many (never a unique solution).
- ›In 2D: the two row vectors are parallel (the parallelogram they span has zero area).
When does a matrix inverse exist?
Two conditions must both hold:
- ›The matrix must be square (n×n) — rectangular matrices never have a full inverse.
- ›The determinant must be non-zero — singular matrices (det = 0) are not invertible.
If both conditions hold, the inverse is unique and satisfies A·A⁻¹ = A⁻¹·A = I.
What dimensions are needed for matrix multiplication?
The rule: (m×n) × (n×p) = (m×p). The inner dimensions must match.
- ›2×3 × 3×4 → valid → result is 2×4
- ›3×2 × 3×2 → invalid (2 ≠ 3)
- ›1×4 × 4×1 → valid → result is 1×1 (dot product)
- ›4×4 × 4×4 → valid → result is 4×4
The calculator shows a real-time dimension message and disables calculate if they don't match.
What is the identity matrix?
The identity matrix Iₙ is n×n with 1s on the diagonal and 0s elsewhere.
- ›A × I = I × A = A — multiplying by the identity leaves any matrix unchanged.
- ›A × A⁻¹ = I — the inverse is defined by this property.
- ›det(I) = 1 — the identity has no scaling effect.
- ›The identity represents the "do nothing" transformation in geometry.
What are real-world uses of matrix operations?
- ›3D graphics: Every object in a game or movie is transformed by 4×4 matrices for position, rotation, and projection.
- ›Machine learning: A neural network forward pass is a series of matrix multiplications.
- ›Statistics: Regression coefficients, covariance matrices, and PCA decomposition all use matrix algebra.
- ›GPS: The Kalman filter updates position estimates using matrix equations every fraction of a second.
- ›Quantum physics: Observable quantities (position, momentum, spin) are represented as matrices called operators.
What keyboard shortcuts does this calculator support?
- ›Enter — run the calculation
- ›Escape — reset all inputs to default and clear localStorage
- ›Tab — move between matrix cells (all cells are keyboard-accessible)
- ›The calculator saves your last inputs automatically; Escape/Reset clears them.