Matrix Calculator
Perform matrix operations with this matrix calculator. Supports addition, subtraction, multiplication, transpose, determinant, and inverse.
This matrix calculator performs addition, subtraction, multiplication, transpose, determinant, and inverse on matrices up to 5x5. Addition and subtraction need matching dimensions, multiplication needs columns of A to equal rows of B, and determinant and inverse need a square matrix. Enter values directly, or use the Identity, Zero, and Random quick-fill buttons to set up a matrix fast.
About Matrix Calculator
Matrix Operations Reference
The six operations supported by the calculator each have different dimensional requirements and produce different shapes of output. Check this table before entering data so the calculator does not reject your matrices.
| Operation | Symbol | Requirement | Result Size |
|---|---|---|---|
| Addition | A + B | Same dimensions | Same as inputs |
| Subtraction | A - B | Same dimensions | Same as inputs |
| Multiplication | A × B | Columns of A = Rows of B | Rows of A × Columns of B |
| Transpose | A^T | Any matrix | Rows and columns swapped |
| Determinant | det(A) | Square matrix only | A single number |
| Inverse | A^(-1) | Square, det ≠ 0 | Same size as input |
How Does Matrix Multiplication Work?
To multiply A (m×n) by B (n×p), each entry of the result is the dot product of a row from A with a column from B. The rule comes directly from the definition of a linear transformation composed with another linear transformation, as set out in Gilbert Strang's MIT 18.06 linear algebra notes.
C[i][j] = Σ A[i][k] × B[k][j]
Worked example. A = [1, 2; 3, 4], B = [5, 6; 7, 8]:
| Position | Calculation | Result |
|---|---|---|
| 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 |
Result: C = [19, 22; 43, 50].
Non-commutativity. Matrix multiplication is not commutative. Using the same A and B above, B × A = [23, 34; 31, 46], which is different from A × B. This is a real algebraic difference, not a quirk of notation - multiplying a rotation by a scaling gives a different result than multiplying a scaling by a rotation, which is why 3D graphics pipelines are strict about the order in which transforms are applied.
How to Calculate a Determinant
The determinant of a square matrix is a single number that encodes whether the matrix has an inverse (det ≠ 0) and how much the matrix scales area or volume as a linear map. For a 2×2 matrix use the diagonal rule; for 3×3 and larger, use cofactor expansion along any row or column.
2×2 matrix:
det([a, b; c, d]) = ad - bc
Example: det([3, 7; 1, 5]) = 3×5 - 7×1 = 15 - 7 = 8.
3×3 matrix (cofactor expansion along the first row):
det(A) = a₁₁(a₂₂a₃₃ - a₂₃a₃₂) - a₁₂(a₂₁a₃₃ - a₂₃a₃₁) + a₁₃(a₂₁a₃₂ - a₂₂a₃₁)
Worked example. A = [2, 1, 3; 0, -1, 2; 1, 4, -1]:
- 2 × det([-1, 2; 4, -1]) = 2 × (1 - 8) = 2 × (-7) = -14
- -1 × det([0, 2; 1, -1]) = -1 × (0 - 2) = -1 × (-2) = 2
- 3 × det([0, -1; 1, 4]) = 3 × (0 + 1) = 3 × 1 = 3
- det(A) = -14 + 2 + 3 = -9
The calculator shows this full cofactor breakdown for 2×2 and 3×3 matrices. For 4×4 and 5×5, it recursively expands along the first row until it reaches 2×2 blocks, which matches the Laplace expansion used in standard linear algebra textbooks.
What Does the Matrix Inverse Mean?
The inverse of a square matrix A, written A⁻¹, is the unique matrix that satisfies A × A⁻¹ = A⁻¹ × A = I, where I is the identity. An inverse exists exactly when det(A) ≠ 0. Geometrically, if A stretches and rotates vectors, then A⁻¹ is the transform that undoes it.
2×2 inverse formula:
A⁻¹ = (1/det(A)) × [d, -b; -c, a]
Worked example. A = [4, 7; 2, 6], det = 24 - 14 = 10.
- A⁻¹ = (1/10) × [6, -7; -2, 4] = [0.6, -0.7; -0.2, 0.4]
- Check: A × A⁻¹ = [4×0.6 + 7×(-0.2), 4×(-0.7) + 7×0.4; 2×0.6 + 6×(-0.2), 2×(-0.7) + 6×0.4] = [1, 0; 0, 1]. Correct.
For matrices larger than 2×2, the calculator uses Gauss-Jordan elimination with partial pivoting. It appends the identity to the right of A, row-reduces until the left half becomes the identity, and the right half is then A⁻¹. This is the method taught in Anton and Rorres' Elementary Linear Algebra and is numerically more stable than computing the classical adjugate for larger matrices.
When det(A) = 0, the matrix is singular. In that case the rows (or columns) are linearly dependent, the transform collapses at least one dimension to zero, and there is no way to undo it. The calculator displays an explicit singular-matrix message rather than returning garbage numbers.
Properties of Matrix Operations
Matrix arithmetic follows a small set of rules that are often tested in exams and used every day in applied work. The following table lists the identities you can rely on, plus the key one that catches people out: multiplication does not commute.
| Property | Formula | Note |
|---|---|---|
| Addition is commutative | A + B = B + A | Always true |
| Addition is associative | (A + B) + C = A + (B + C) | Grouping does not matter |
| Multiplication is NOT commutative | AB ≠ BA (generally) | Order matters |
| Multiplication is associative | (AB)C = A(BC) | Grouping does not matter |
| Distributive | A(B + C) = AB + AC | Expands the same way as scalars |
| Transpose of product | (AB)^T = B^T × A^T | Note the order reversal |
| Determinant of product | det(AB) = det(A) × det(B) | Useful shortcut |
| Inverse of product | (AB)⁻¹ = B⁻¹ × A⁻¹ | Note the order reversal |
| Det of transpose | det(A^T) = det(A) | Transpose does not change det |
Where Are Matrices Used in the Real World?
Matrices show up any time you have to apply the same linear operation to many pieces of data at once. Modern graphics cards, machine learning libraries, and spreadsheet solvers are all matrix engines underneath.
| Field | Application | Typical Size |
|---|---|---|
| Computer graphics | Rotation, scaling, and translation transforms in 3D are 4×4 matrices applied per vertex | 4×4 |
| Machine learning | A single weight matrix in a large language model can exceed 10,000 × 10,000 | Very large |
| Physics | Quantum mechanics uses Hermitian operators; moment-of-inertia tensors are 3×3 | 3×3 and up |
| Economics | Wassily Leontief's 1973 Nobel Prize work on input-output models is pure matrix algebra | Sector count |
| Engineering | Finite element analysis assembles stiffness matrices to model stress in structures | Millions of rows |
| Statistics | Multiple regression uses (X^T X)⁻¹ X^T y, where X is the design matrix | Samples × predictors |
| Cryptography | Hill cipher encrypts blocks by multiplying with an invertible matrix mod 26 | 2×2 or 3×3 |
Common Mistakes and Edge Cases
Matrix problems fail in predictable ways. These are the traps the calculator warns about and that students lose marks for in exams.
- Swapping row and column counts. A 2×3 matrix has 2 rows and 3 columns. Row count comes first. Getting this wrong turns every dimension check into guesswork.
- Trying to multiply incompatible shapes. 2×3 times 2×3 does not work. You need 2×3 times 3×k. The calculator shows the exact reason when it rejects a multiplication.
- Assuming AB = BA. Even for square matrices of the same size, AB and BA are usually different matrices. Rotate-then-scale is not the same as scale-then-rotate.
- Asking for the inverse of a singular matrix. If det(A) = 0, no inverse exists. Check the determinant first; a result of 0 (or very close to it, like 1e-12 from floating point) means stop.
- Floating-point determinants close to zero. Because the inverse uses Gauss-Jordan elimination, the calculator treats |det| < 1e-10 as singular to avoid dividing by near-zero pivots and producing huge, meaningless numbers.
- Forgetting (AB)⁻¹ = B⁻¹ A⁻¹. The order flips. This is easy to miss and is a common exam trap.
Tips for Using This Calculator Efficiently
A few small habits make matrix work much faster and reduce arithmetic errors.
- Set the size before typing values. Changing the row or column count after entering data preserves overlapping cells, but resizing larger pads with zeros and resizing smaller discards the extras. Set the dimensions first.
- Use Identity as a starting point. The Identity button gives you a matrix that already satisfies A × I = A, so it is a useful sanity check - multiply any matrix by the identity and the result should match the input.
- Check the determinant before asking for the inverse. If det(A) is zero or very small, the inverse is unstable or does not exist. The determinant step-by-step view also helps you spot a row or column of zeros instantly.
- Use integers where possible. Floating-point arithmetic in any matrix tool (including this one) will show small rounding artefacts like 0.9999999 instead of 1. Working with whole numbers where you can makes the output cleaner.
- Transpose is a shape check. If you are not sure which way round your data is, transposing it is cheap and shows you the alternative shape. This is especially helpful when lining up A and B for multiplication.
For solving systems of linear equations (which matrices represent compactly), the equation solver handles 2×2 systems using Cramer's rule - which is itself a ratio of determinants. To visualise mathematical functions alongside matrix work, the graphing calculator plots any expression, and the scientific calculator handles the arithmetic inside each cell if you want to compute entries by hand before entering them.
Every calculation runs in your browser. No matrix data is sent to any server.
Sources
Frequently Asked Questions
What matrix sizes are supported?
You can work with matrices from 1x1 up to 5x5. Adjust the row and column count using the dropdown selectors next to each matrix label.
What operations are available?
You can add, subtract, or multiply two matrices. Single-matrix operations include transpose, determinant (for square matrices), and inverse (for non-singular square matrices). Each operation checks dimensions automatically.
What happens if my matrix has no inverse?
A matrix with a determinant of zero is called singular and has no inverse. The calculator will display a clear message explaining this. You can check the determinant first to see if an inverse exists.
Does it show step-by-step work?
Yes, the determinant operation includes a step-by-step cofactor expansion for 2x2 and 3x3 matrices. This helps you follow the calculation and verify your own work.
Why can't I multiply these two matrices?
Matrix multiplication requires the number of columns in matrix A to equal the number of rows in matrix B. For example, a 2x3 matrix can multiply a 3x2 matrix, but not a 2x2. The calculator shows a clear error when dimensions don't match.
Related Tools
Link to this tool
Copy this HTML to link to this tool from your website or blog.
<a href="https://toolboxkit.io/tools/matrix-calculator/" title="Matrix Calculator - Free Online Tool">Try Matrix Calculator on ToolboxKit.io</a>