Matrix Calculator
A × B
| Row | Col 1 | Col 2 | Col 3 | Col 4 |
|---|---|---|---|---|
| 1 | 16 | 9 | 11 | 11 |
| 2 | 7 | 7 | 10 | 8 |
| 3 | 19 | 18 | 6 | 13 |
| 4 | 13 | 1 | 7 | 4 |
This matrix calculator adds, subtracts and multiplies two matrices, and finds the transpose, powers, scalar multiples, determinant and inverse of either one. Entries may be integers, decimals or fractions, and results are exact.
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, and the entry in row i and column j is written aᵢⱼ. Matrices are a compact way to store and manipulate many numbers at once, and they are the language of linear algebra. They describe systems of linear equations, rotations and scaling in computer graphics, networks and transitions in probability, and the layers of neural networks.
Type each matrix with one row per line and the entries separated by spaces or commas. Entries can be whole numbers, decimals or fractions such as 3/4. The calculator works with exact fractions throughout, so an inverse such as 1/3 is shown exactly rather than as a rounded decimal. Choose an operation to combine A and B, or to act on one of them alone. The default operation multiplies the two 4 × 4 example matrices.
Square matrices, with as many rows as columns, have special properties. Only they have determinants, inverses and powers. The identity matrix I, with ones on the main diagonal and zeros elsewhere, plays the role of the number 1: multiplying any matrix by I leaves it unchanged.
Matrix addition
Two matrices can be added only if they have the same dimensions. The sum is found entry by entry: each entry of A + B is the sum of the entries in the same position of A and B. Adding a 2 × 3 matrix to a 3 × 2 matrix is undefined, even though both have six entries.
Matrix addition behaves like ordinary addition. It is commutative, so A + B = B + A, and associative, so (A + B) + C = A + (B + C). The zero matrix, filled with zeros, is the additive identity. A related operation is scalar multiplication: multiplying a matrix by a number k multiplies every entry by k, so 3A triples each entry. Scalar multiplication distributes over addition, k(A + B) = kA + kB.
| A | B | A + B |
|---|---|---|
| [1 2; 3 4] | [5 0; −1 2] | [6 2; 2 6] |
Matrix subtraction
Subtraction follows the same rule as addition: the matrices must have the same size, and each entry of A − B is the entry of A minus the matching entry of B. It is the same as adding A and the negative of B, −B = (−1)B. Unlike addition, subtraction is not commutative; B − A is the negative of A − B.
| A | B | A − B |
|---|---|---|
| [1 2; 3 4] | [5 0; −1 2] | [−4 2; 4 2] |
Matrix multiplication
Matrix multiplication is not done entry by entry. To multiply A by B, the number of columns of A must equal the number of rows of B. If A is m × n and B is n × p, the product AB is m × p. Each entry of the product is a dot product: the entry in row i and column j of AB is found by multiplying the entries of row i of A by the matching entries of column j of B and adding the results.
For example, with A = [1 2; 3 4] and B = [5 0; −1 2], the top-left entry of AB is 1 × 5 + 2 × (−1) = 3, the top-right is 1 × 0 + 2 × 2 = 4, the bottom-left is 3 × 5 + 4 × (−1) = 11 and the bottom-right is 3 × 0 + 4 × 2 = 8. So AB = [3 4; 11 8].
The most important difference from ordinary multiplication is that order matters. In general AB ≠ BA; for the same two matrices, BA = [5 10; 5 6]. Sometimes one product is defined and the other is not, as when A is 2 × 3 and B is 3 × 4. Multiplication is still associative, (AB)C = A(BC), and distributes over addition, A(B + C) = AB + AC. Another surprise is that the product of two non-zero matrices can be the zero matrix.
The definition looks arbitrary until you see what it represents. A matrix can stand for a linear transformation, such as a rotation or a stretch, and multiplying matrices composes the transformations: applying B and then A is the same as applying AB. This is why graphics software can combine dozens of rotations, scalings and translations into a single matrix and apply it to millions of points.
Multiplying two n × n matrices with the standard method takes n³ multiplications, so doubling the size makes the work eight times larger. Faster algorithms exist, beginning with Strassen's method in 1969, and optimized matrix multiplication sits at the heart of scientific computing and machine learning.
| A | B | AB | BA |
|---|---|---|---|
| [1 2; 3 4] | [5 0; −1 2] | [3 4; 11 8] | [5 10; 5 6] |
Power of a matrix
Raising a square matrix to a whole-number power means multiplying it by itself repeatedly: A² = AA and A³ = AAA. Only square matrices can be raised to powers, because the product must stay the same size to keep multiplying. By convention A⁰ = I, the identity matrix, and for an invertible matrix A⁻ⁿ = (A⁻¹)ⁿ.
Matrix powers model repeated processes. If a matrix gives the probabilities of moving between states in one step of a Markov chain, its nth power gives the probabilities after n steps. The Fibonacci numbers appear in the powers of [1 1; 1 0]: its nth power is [Fₙ₊₁ Fₙ; Fₙ Fₙ₋₁]. The calculator uses repeated squaring, which needs only about log₂ n multiplications.
| A | A² | A³ |
|---|---|---|
| [1 1; 1 0] | [2 1; 1 1] | [3 2; 2 1] |
Transpose of a matrix
The transpose of A, written Aᵀ, flips the matrix over its main diagonal, turning rows into columns. The entry in row i, column j of Aᵀ is the entry in row j, column i of A, so an m × n matrix becomes n × m. Transposing twice gives back the original, and the transpose of a product reverses the order: (AB)ᵀ = BᵀAᵀ. A matrix equal to its own transpose is called symmetric.
| A (2 × 3) | Aᵀ (3 × 2) |
|---|---|
| [1 2 3; 4 5 6] | [1 4; 2 5; 3 6] |
Determinant of a matrix
The determinant is a single number computed from a square matrix, written det(A) or |A|. It measures how the matrix scales area or volume when viewed as a transformation: a 2 × 2 matrix with determinant 3 turns every unit square into a parallelogram of area 3. A negative determinant means the transformation also flips orientation, like a mirror, and a determinant of zero means it collapses space into a lower dimension.
For a 2 × 2 matrix [a b; c d], the determinant is ad − bc. For [1 2; 3 4] that is 1 × 4 − 2 × 3 = −2.
For a 3 × 3 matrix [a b c; d e f; g h i], one method is cofactor expansion along the first row: det = a(ei − fh) − b(di − fg) + c(dh − eg). Each term multiplies an entry of the row by the determinant of the 2 × 2 matrix left after deleting that entry's row and column, with signs alternating +, −, +. For example, det [2 0 1; 1 3 2; 1 1 1] = 2(3 − 2) − 0(1 − 2) + 1(1 − 3) = 0, so that matrix is singular. The same expansion works along any row or column, and for larger matrices it is applied recursively.
Cofactor expansion grows extremely quickly, needing about n! operations, so practical software uses row reduction instead. Adding a multiple of one row to another does not change the determinant, swapping two rows changes its sign, and the determinant of a triangular matrix is the product of its diagonal. Reducing to triangular form therefore gives the determinant in about n³ steps. This calculator does that with exact fractions.
Determinants obey several useful rules. det(AB) = det(A) × det(B), det(Aᵀ) = det(A), and det(kA) = kⁿ det(A) for an n × n matrix. Most importantly, a square matrix has an inverse exactly when its determinant is not zero. A system of n linear equations in n unknowns has a single unique solution exactly when the determinant of its coefficient matrix is non-zero, which is the basis of Cramer's rule.
| Matrix | Method | Determinant |
|---|---|---|
| [1 2; 3 4] | 1·4 − 2·3 | −2 |
| [2 0 1; 1 3 2; 1 1 1] | 2(3−2) − 0(1−2) + 1(1−3) | 0 |
| [3 0 0; 0 2 0; 0 0 5] | product of diagonal | 30 |
Inverse of a matrix
The inverse of a square matrix A is the matrix A⁻¹ for which AA⁻¹ = A⁻¹A = I. It plays the role of division: to solve the matrix equation AX = B, multiply both sides on the left by A⁻¹ to get X = A⁻¹B. A matrix has an inverse only if its determinant is non-zero; a matrix without one is called singular.
For a 2 × 2 matrix [a b; c d], swap a and d, negate b and c, and divide by the determinant: A⁻¹ = (1 ÷ (ad − bc)) [d −b; −c a]. For [1 2; 3 4], the determinant is −2, so the inverse is [−2 1; 3/2 −1/2]. Multiplying back confirms that the product is the identity.
For larger matrices, the standard method is Gauss-Jordan elimination. Write A next to the identity matrix, [A | I], then use row operations to turn the left half into I. The same operations turn the right half into A⁻¹. If a row of zeros appears on the left, the matrix is singular. Another method builds the inverse from the matrix of cofactors divided by the determinant, but it is far slower for anything bigger than 3 × 3.
Inverses satisfy (A⁻¹)⁻¹ = A and (AB)⁻¹ = B⁻¹A⁻¹, with the order reversed just as with transposes. In numerical work, computing the inverse explicitly is often avoided in favor of solving the equations directly, which is faster and less sensitive to rounding. Exact fraction arithmetic, as used here, has no rounding error at all.
| A | det(A) | A⁻¹ |
|---|---|---|
| [1 2; 3 4] | −2 | [−2 1; 3/2 −1/2] |
| [2 1; 5 3] | 1 | [3 −1; −5 2] |
Frequently asked questions
How do I enter a matrix?
Put each row on its own line and separate entries with spaces or commas. For example, type 1 2 on the first line and 3 4 on the second for a 2 × 2 matrix.
When can two matrices be multiplied?
When the number of columns in the first equals the number of rows in the second. A 2 × 3 matrix times a 3 × 4 matrix gives a 2 × 4 result.
Why is AB different from BA?
Matrix multiplication combines rows of the first matrix with columns of the second, so swapping the order generally changes the result, or makes it undefined.
How do I find the inverse of a 2 × 2 matrix?
For [a b; c d], swap a and d, change the signs of b and c, and divide every entry by ad − bc.
What does a determinant of zero mean?
The matrix is singular: it has no inverse, its rows are linearly dependent, and the matching system of equations has either no solution or infinitely many.
How do I find the inverse of a 3 × 3 matrix?
First compute the determinant; if it is zero, the matrix has no inverse. Otherwise one formula is A⁻¹ = adj(A) ÷ det(A), where the adjugate is the transposed matrix of cofactors. Row-reducing [A | I] until the left side becomes I leaves A⁻¹ on the right with less arithmetic, and the calculator's inverse option does this for you.
Updated by Calculator.hair. How we build and check our calculators