Matrix Calculator

Perform matrix operations online: addition, subtraction, multiplication, transpose, determinant, and inverse. Enter rows separated by newlines, values by spaces.

enter matrices
Operation
Matrix A
Matrix B (for A±B, A×B)
Result (click to copy)

Choosing the Right Operation

Combining or comparing datasets
Addition and subtraction combine matrices element-by-element — useful when each matrix represents a layer of the same kind of data (e.g. sales by region in two different months).
Transforming or chaining transformations
Multiplication is how you apply or chain linear transformations (rotations, scaling, systems of equations) — remember it's not commutative, so A×B usually isn't the same as B×A.
Solving a system of linear equations
The inverse of a matrix lets you solve Ax=b directly as x=A⁻¹b. This only works when A is square and its determinant is non-zero — if it's singular, the system either has no unique solution or infinitely many.

How to Use the Matrix Calculator

  1. Enter Matrix A — type rows separated by new lines, values separated by spaces or commas. Example: '1 2 3' on line 1, '4 5 6' on line 2 for a 2×3 matrix.
  2. Enter Matrix B — required for addition, subtraction, and multiplication. Not needed for transpose or determinant.
  3. Select operation — choose from addition (A+B), subtraction (A−B), multiplication (A×B), transpose, or determinant.
  4. Click Calculate — the result matrix appears with formatted alignment.
  5. Check dimensions — addition/subtraction require identical dimensions. Multiplication requires columns of A = rows of B. Determinant requires square matrix.
📐 Dimension rule for multiplication: If A is m×n and B is n×p, then A×B is m×p. The inner dimensions must match. A 2×3 matrix multiplied by a 3×4 matrix gives a 2×4 result. A 3×2 times 2×3 gives 3×3. A 2×3 times 2×3 is IMPOSSIBLE — inner dimensions (3 and 2) don't match.

Understanding Matrix Operations

📊 Matrix Basics
A matrix is a rectangular array of numbers arranged in rows and columns. An m×n matrix has m rows and n columns. A 2×3 matrix has 2 rows and 3 columns (6 elements total). Matrices represent systems of equations, linear transformations, data tables, and relationships between variables.
➕ Addition and Subtraction
Only possible for matrices of identical dimensions. Add/subtract corresponding elements: (A+B)ᵢⱼ = Aᵢⱼ + Bᵢⱼ. The result has the same dimensions as the inputs. Commutative: A+B = B+A. Not commutative for multiplication: generally AB ≠ BA.
✖️ Matrix Multiplication
A×B: each element of the result is the dot product of a row from A and a column from B. (A×B)ᵢⱼ = Σ Aᵢₖ × Bₖⱼ. NOT commutative (AB ≠ BA in general). Associative: (AB)C = A(BC). Represents applying transformations in sequence.
🔄 Transpose
Flips matrix over its diagonal — rows become columns. (Aᵀ)ᵢⱼ = Aⱼᵢ. A 2×3 matrix transposed becomes 3×2. Used in linear algebra proofs, machine learning (normal equations), and rotation matrices. (AB)ᵀ = BᵀAᵀ (note reversed order).
🔢 Determinant
A scalar value calculated from a square matrix. det(A) ≠ 0: matrix is invertible (non-singular). det(A) = 0: matrix is singular (no inverse). Geometrically: |det(A)| represents the scaling factor of area/volume under the linear transformation A. Used in Cramer's rule, eigenvalue calculation, and change of variables in integrals.
🔀 Matrix Inverse
A⁻¹ exists only when det(A) ≠ 0. A × A⁻¹ = I (identity matrix). Used to solve systems of equations: Ax = b → x = A⁻¹b. For 2×2 matrix [[a,b],[c,d]]: inverse = (1/det) × [[d,−b],[−c,a]]. For larger matrices, Gaussian elimination or LU decomposition is used.

Matrices in Science and Technology

Systems of equations

A system of n linear equations in n unknowns can be written as Ax = b where A is the coefficient matrix, x is the unknown vector, and b is the constants vector. For 2x + 3y = 7 and x − y = 1: A = [[2,3],[1,−1]], b = [7,1]. Solving by matrix inversion: x = A⁻¹b. This matrix approach scales to thousands of equations in computational physics, engineering simulation, and economic modelling where manual solving is impossible.

Machine learning and data science

Machine learning is fundamentally matrix operations. Training data is stored as a matrix (rows = samples, columns = features). Neural network layers apply matrix multiplication to transform inputs. Linear regression solution: θ = (XᵀX)⁻¹Xᵀy (the normal equation — involves matrix multiplication, transpose, and inverse). Principal Component Analysis (PCA) uses matrix decomposition. Understanding matrix operations is prerequisite knowledge for machine learning implementation.

Computer graphics transformations

Every transformation in 3D graphics is a matrix multiplication. Translation, rotation, scaling, and projection are all 4×4 matrices. Composing transformations: multiply their matrices together. A scene with 1 million vertices transformed by a combined model-view-projection matrix requires 1 million matrix-vector multiplications per frame — modern GPUs are optimised specifically for this parallel matrix computation. Game engines and 3D software expose these as matrix operations.

📐 Matrix operation quick reference: Same dimensions required: A+B, A−B. Columns of A = rows of B required: A×B. Square matrix required: det(A), A⁻¹. Any matrix: Aᵀ. Identity matrix I: any matrix × I = original matrix (like multiplying by 1). Zero matrix O: any matrix + O = original (like adding 0). These rules govern all matrix arithmetic.

Matrix Inverse Formula

A matrix has an inverse only if it's square and det(A) ≠ 0. This calculator finds A⁻¹ using Gauss-Jordan elimination: augment A with the identity matrix, row-reduce A to the identity, and the identity side becomes A⁻¹.

Worked example

For A = [[4, 7], [2, 6]]: det(A) = 4×6 − 7×2 = 24 − 14 = 10 (non-zero, so an inverse exists). For a 2×2 matrix specifically, A⁻¹ = (1/det) × [[d, −b], [−c, a]] = (1/10) × [[6, −7], [−2, 4]] = [[0.6, −0.7], [−0.2, 0.4]]. Check: A × A⁻¹ should give the identity matrix [[1,0],[0,1]].

If det(A) = 0, the matrix is singular — no inverse exists. This calculator detects this and explains why, rather than showing a broken or infinite result.

Avoid These Mistakes

Adding or subtracting mismatched dimensions
A and B must have identical dimensions for addition/subtraction. A 2×3 matrix can't be added to a 2×2 — the calculator now checks this and explains exactly which dimensions don't match.
Assuming matrix multiplication is commutative
A×B usually isn't equal to B×A, and one order might not even be defined while the other is. Always check which order your problem actually requires.
Trying to invert a non-square or singular matrix
Only square matrices can have an inverse, and even then only if the determinant is non-zero. A singular matrix (det = 0) has no inverse — this isn't a calculation error, it's a mathematical fact about that specific matrix.

Frequently Asked Questions

How do I enter a matrix?
Enter each row on a new line, with values separated by spaces or commas. Example: a 2×3 matrix would be entered as two lines with 3 values each: '1 2 3' on line 1, '4 5 6' on line 2.
When can I multiply two matrices?
Matrix multiplication A×B is only possible when the number of columns in A equals the number of rows in B. A 2×3 matrix can multiply a 3×4 matrix (result: 2×4). Matrix multiplication is not commutative — A×B ≠ B×A in general.
What is a determinant?
The determinant is a scalar value calculated from a square matrix. It tells you if the matrix is invertible (non-zero determinant) or singular (zero determinant). Used in solving systems of equations, finding area/volume, and linear algebra.

References

📐 Gauss-Jordan Elimination
The row-reduction method this calculator uses to compute the inverse — standard material in any linear algebra course, and the same method taught for solving systems of linear equations.
📄 Your linear algebra course or textbook
This tool covers the six most common matrix operations for practical-sized matrices — for eigenvalues, eigenvectors, or other advanced linear algebra topics, consult your course material.