Matrix Calculator
PrintIn mathematics, a matrix (plural: matrices) is a rectangular array of numbers, symbols, or algebraic expressions arranged in rows and columns. Matrices serve as fundamental tools in linear algebra, computer graphics (for 3D rendering and rotation), physics, statistics, calculus, and machine learning neural networks.
The dimensions of a matrix are written as m × n, indicating it has m rows and n columns. Each individual value inside a matrix is called an element, represented by its coordinate subscript. For instance, the element a_1,3 sits in the first row and the third column of matrix A.
Our free online Matrix Calculator performs a wide range of calculations on matrices up to 4 × 4 dimensions, including element-wise arithmetic, dot-product multiplications, transposes, powers, determinants, and matrix inversions.
Matrix Addition and Subtraction
Matrix addition and subtraction can only be performed on matrices of the exact same size (matching m × n dimensions). You cannot add a 2×3 matrix to a 3×2 matrix, nor can you add a 4×4 to a 3×3.
If the sizes match, the operation is performed element-wise by adding or subtracting the values in corresponding positions:
A = [1, 2; 3, 4] and B = [5, 6; 7, 8]
– Addition (A + B):
c_1,1 = 1 + 5 = 6 | c_1,2 = 2 + 6 = 8
c_2,1 = 3 + 7 = 10 | c_2,2 = 4 + 8 = 12
C = [6, 8; 10, 12]
– Subtraction (A – B):
c_1,1 = 1 - 5 = -4 | c_1,2 = 2 - 6 = -4
c_2,1 = 3 - 7 = -4 | c_2,2 = 4 - 8 = -4
C = [-4, -4; -4, -4]
Matrix Multiplication (Scalar vs. Matrix-Matrix)
Scalar Multiplication
To multiply a matrix by a single scalar number, simply multiply each element in the matrix by that scalar:
5 × [1, 2; 3, 4] = [5, 10; 15, 20]
Matrix-Matrix Multiplication
Multiplying two matrices is more complex. You can only multiply matrix A by matrix B if the number of columns in A equals the number of rows in B. If A is m × p and B is p × n, the resulting matrix C will be m × n.
Matrix multiplication is NOT commutative: AB ≠ BA. In fact, computing AB does not guarantee that BA is even dimensionally valid.
The values of C are calculated using the dot product of rows from A and columns from B:
c_i,j = (row i of A) • (col j of B)
Multiplication Example (2×3 Matrix by 3×4 Matrix)
Let’s multiply A (2×3) and B (3×4):
A = [1, 2, 1; 3, 4, 1]
B = [5, 6, 1, 1; 7, 8, 1, 1; 1, 1, 1, 1]
Resulting matrix C will be 2×4:
– c_1,1 = (1×5) + (2×7) + (1×1) = 20
– c_1,2 = (1×6) + (2×8) + (1×1) = 23
– c_1,3 = (1×1) + (2×1) + (1×1) = 4
– c_1,4 = (1×1) + (2×1) + (1×1) = 4
– c_2,1 = (3×5) + (4×7) + (1×1) = 44
– c_2,2 = (3×6) + (4×8) + (1×1) = 51
– c_2,3 = (3×1) + (4×1) + (1×1) = 8
– c_2,4 = (3×1) + (4×1) + (1×1) = 8
C = [20, 23, 4, 4; 44, 51, 8, 8]
Matrix Transpose and Powers
- Transpose (A^T): Flipping a matrix over its main diagonal. This swaps the row and column subscripts:
a_i,jin matrix A becomesa_j,iin the transposed matrix. Anm × nmatrix transposed becomes ann × mmatrix. - Matrix Powers (A^2, A^3…): Multiplying a matrix by itself. Only square matrices (same number of rows and columns) can be raised to a power, as a non-square matrix cannot satisfy the rows-to-columns multiplication rule with itself.
Determinant of a Matrix
The determinant is a scalar value computed from square matrices. It is represented as |A| or det(A), and is essential for finding matrix inverses and solving systems of linear equations.
2×2 Determinant (Leibniz Formula)
For a 2×2 matrix A = [a, b; c, d]:
det(A) = ad - bc
Example: For A = [2, 4; 6, 8]:
det(A) = (2×8) - (4×6) = 16 - 24 = -8.
3×3 Determinant (Laplace Cofactor Expansion)
For a 3×3 matrix, expand along the first row:
det([a, b, c; d, e, f; g, h, i]) = a × det([e, f; h, i]) - b × det([d, f; g, i]) + c × det([d, e; g, h])
This reduces to the algebraic formula:
det(A) = a(ei - fh) - b(di - fg) + c(dh - eg)
4×4 and Higher Determinants
These are computed similarly using the Laplace expansion, expanding along a row or column to reduce a 4×4 matrix into four 3×3 determinants, alternating signs (+ - + -). Because this process scales exponentially in complexity, computational solvers use triangular decomposition algorithms (such as LU Decomposition) for high-order matrices.
Inverse of a Matrix
The inverse of a square matrix A is denoted as A^-1. It satisfies the equation:
A × A^-1 = A^-1 × A = I
Where I is the Identity Matrix (a square matrix with 1s on the diagonal and 0s elsewhere, acting as the number “1” in matrix algebra). If det(A) = 0, the matrix has no inverse and is called a singular matrix.
2×2 Matrix Inversion Formula
To invert a 2×2 matrix A = [a, b; c, d]:
A^-1 = [d, -b; -c, a] / det(A)
Example: Invert A = [2, 4; 3, 7].
– det(A) = (2×7) - (4×3) = 2
– Swap diagonal elements, negate off-diagonals: [7, -4; -3, 2]
– Divide by determinant: A^-1 = [3.5, -2; -1.5, 1]
Solve exponents with our Exponent Calculator or handle general functions with the Scientific Calculator.
Frequently Asked Questions (FAQ)
What is a singular matrix?
A singular matrix is a square matrix that has a determinant of exactly zero. Singular matrices do not have an inverse matrix, meaning they cannot be inverted to solve linear algebra equations. Geometrically, they compress space into a lower dimension.
Why is matrix multiplication not commutative?
Matrix multiplication combines rows of the first matrix with columns of the second matrix. Because the operations depend on the order of dimensions, swapping the matrices changes which vectors are paired, resulting in a completely different output: AB ≠ BA.
What is the Identity Matrix?
The Identity Matrix (I) is a square matrix with 1s along the main diagonal (from top-left to bottom-right) and 0s in all other elements. Multiplying any matrix A by the identity matrix of matching dimensions returns the original matrix: A × I = A.
How do you transpose a matrix?
To transpose a matrix, you swap its rows and columns. The first row of the original matrix becomes the first column of the transposed matrix, the second row becomes the second column, and so on. Visually, the matrix is flipped across its diagonal axis.