Matrix Operations Reference — Interactive Cheatsheet
A comprehensive reference of 20+ matrix operations organized by category. Each operation includes the formula, a visual example with small matrices, and a "Try It" mini-calculator. Search by name or filter by category to quickly find any operation.
Understanding Matrix Operations: A Complete Guide
Matrix operations form the computational backbone of linear algebra, and linear algebra is the mathematical language of modern science, engineering, and machine learning. Every neural network forward pass is a sequence of matrix multiplications and element-wise nonlinearities. Every least-squares regression reduces to solving a matrix equation. Every principal component analysis hinges on eigenvalue decomposition. Mastering matrix operations is not merely academic; it is a practical prerequisite for working effectively with data, models, and simulations.
Matrices encode linear transformations: rotations, reflections, scalings, shears, and projections. A 2×2 matrix acting on a 2D vector produces another 2D vector, and the matrix completely specifies how the entire plane is warped. The determinant measures how areas (or volumes in higher dimensions) scale under the transformation. If the determinant is zero, the transformation collapses the space into a lower dimension, and the matrix is singular (non-invertible). If the determinant is negative, the transformation includes a reflection that reverses orientation.
Basic Operations: Addition, Scaling, and Multiplication
Matrix addition and scalar multiplication are straightforward element-wise operations. Given matrices A and B of the same dimensions m×n, their sum C = A + B has entries C(i,j) = A(i,j) + B(i,j). Scalar multiplication scales every entry: (cA)(i,j) = c · A(i,j). These operations satisfy the familiar commutative and associative laws: A + B = B + A, and c(A + B) = cA + cB.
Matrix multiplication is far more interesting and subtle. The product AB requires the number of columns of A to equal the number of rows of B. If A is m×n and B is n×p, then AB is m×p with entries (AB)(i,j) = sum over k of A(i,k)B(k,j). This is the dot product of row i of A with column j of B. Matrix multiplication is associative, A(BC) = (AB)C, and distributive, A(B+C) = AB + AC, but crucially not commutative: AB does not generally equal BA, even when both products are defined. This non-commutativity reflects the fact that the order of geometric transformations matters: rotating then scaling is different from scaling then rotating.
The Transpose and Its Properties
The transpose of a matrix A, written A^T, flips the matrix across its main diagonal: (A^T)(i,j) = A(j,i). Rows become columns and columns become rows. The transpose satisfies several important identities: (A^T)^T = A, (A+B)^T = A^T + B^T, (cA)^T = cA^T, and the critical reversal law (AB)^T = B^T A^T. A matrix that equals its own transpose (A = A^T) is called symmetric. Symmetric matrices arise naturally as covariance matrices, Hessians (second-derivative matrices), and adjacency matrices of undirected graphs. They have the special property that all their eigenvalues are real, and their eigenvectors can be chosen to be orthogonal.
The conjugate transpose (or Hermitian transpose), written A*, generalizes the transpose to complex matrices by also taking the complex conjugate of each entry. A matrix equal to its conjugate transpose is Hermitian, and Hermitian matrices are the complex analog of symmetric matrices. In quantum mechanics, observable quantities correspond to Hermitian operators, guaranteeing real eigenvalues (measurement outcomes).
Determinant, Trace, and Rank
The determinant of a square matrix is a scalar that encodes several key properties. For a 2×2 matrix [[a,b],[c,d]], det = ad - bc. For 3×3 and larger, the determinant is computed by cofactor expansion or, more efficiently, by LU decomposition (the determinant equals the product of the diagonal entries of U, times the sign of the permutation). The determinant is zero if and only if the matrix is singular. The absolute value of the determinant gives the factor by which the linear transformation scales volumes. The determinant is multiplicative: det(AB) = det(A) det(B). And det(A^T) = det(A).
The trace of a square matrix is the sum of its diagonal entries: tr(A) = A(1,1) + A(2,2) + ... + A(n,n). The trace equals the sum of the eigenvalues, and the determinant equals the product of the eigenvalues. The trace is invariant under cyclic permutations: tr(ABC) = tr(CAB) = tr(BCA). The rank of a matrix is the number of linearly independent rows (or equivalently columns), which equals the number of nonzero singular values. A matrix is full rank when its rank equals the smaller of its dimensions.
Matrix Decompositions
Matrix decompositions (factorizations) are the workhorses of numerical linear algebra. LU decomposition factors A = LU where L is lower triangular and U is upper triangular; it is the basis of Gaussian elimination and is the fastest way to solve Ax = b for a single system. With partial pivoting (PA = LU), it is numerically stable for most practical matrices.
QR decomposition factors A = QR where Q is orthogonal (Q^T Q = I) and R is upper triangular. Because orthogonal transformations preserve norms and angles, QR decomposition is more numerically stable than LU for ill-conditioned problems. It is the standard method for solving least-squares problems (minimize ||Ax - b||) and for computing eigenvalues via the QR algorithm.
Singular Value Decomposition (SVD) is the most powerful and general decomposition. Any m×n matrix A can be written as A = U Σ V^T, where U is m×m orthogonal, V is n×n orthogonal, and Σ is m×n diagonal with non-negative singular values σ1 ≥ σ2 ≥ ... ≥ 0. The singular values reveal the rank (number of nonzero σ's), the condition number (σ1/σ_min), and the best low-rank approximation (truncate to the k largest singular values). SVD underlies PCA, latent semantic analysis, recommender systems, image compression, and the pseudoinverse.
Special Matrices and Their Properties
Several matrix types appear repeatedly across applications. The identity matrix I has ones on the diagonal and zeros elsewhere; it is the multiplicative identity (AI = IA = A). Diagonal matrices have nonzero entries only on the main diagonal; they are trivially invertible (invert each diagonal entry) and their eigenvalues are the diagonal entries. Triangular matrices (upper or lower) are square matrices with zeros above or below the diagonal; they arise in LU decomposition and are easy to solve via forward or back substitution.
Orthogonal matrices satisfy Q^T Q = QQ^T = I, meaning their rows and columns are orthonormal vectors. Orthogonal transformations preserve lengths and angles (they are rotations and reflections). Their determinant is ±1. Positive definite matrices are symmetric matrices where all eigenvalues are positive, equivalently where x^T A x > 0 for all nonzero vectors x. They arise as covariance matrices, Hessians of convex functions, and kernel matrices. The Cholesky decomposition A = LL^T exists if and only if A is symmetric positive definite, and it is twice as efficient as LU decomposition.
Frequently Asked Questions
What are the most important matrix operations in linear algebra?
The core operations are addition, scalar multiplication, matrix multiplication, transpose, inverse, and determinant. Matrix multiplication uses dot products of rows and columns and is not commutative. The inverse reverses a transformation, and the determinant indicates invertibility and volume scaling. For advanced work, eigendecomposition, SVD, LU, and QR decomposition are essential.
What is the difference between element-wise and matrix multiplication?
Element-wise (Hadamard) multiplication multiplies corresponding entries of same-sized matrices: C(i,j) = A(i,j)B(i,j). Matrix multiplication computes C(i,j) as the dot product of row i of A with column j of B, requires matching inner dimensions, and is not commutative. Element-wise is used in gating mechanisms (LSTMs); matrix multiplication in linear layers.
When is a matrix invertible and how do you compute the inverse?
A square matrix is invertible if and only if its determinant is nonzero (equivalently: columns are linearly independent, rank equals size, all eigenvalues are nonzero). For 2×2: swap diagonals, negate off-diagonals, divide by det. For larger matrices, use Gauss-Jordan elimination or LU decomposition. In practice, solving Ax = b directly is preferred over computing the explicit inverse.
What are eigenvalues and eigenvectors used for?
Eigenvectors are directions that a matrix only scales (not rotates): Av = λv. Eigenvalues λ are the scaling factors. PCA uses eigenvectors of the covariance matrix. Google PageRank uses the dominant eigenvector of the link matrix. Stability analysis checks whether eigenvalues have negative real parts. Eigendecomposition enables efficient matrix powers and exponentials.
What is the difference between LU, QR, and SVD decomposition?
LU factors A = LU (lower × upper triangular) for fast linear system solving. QR factors A = QR (orthogonal × upper triangular) for more stable least-squares. SVD factors A = UΣV^T for any matrix, revealing rank, condition number, and best low-rank approximation. SVD is the most general; LU is the fastest for square systems; QR is the standard for least-squares.
Related Tools
- Matrix Multiplication Calculator — step-by-step matrix product with dimension checking
- Determinant Calculator — cofactor expansion and LU-based determinant
- Eigenvector Step Solver — characteristic polynomial and null space computation
- Numerical Stability Guide — condition numbers and floating-point precision analysis
Built by Michael Lip. Try the ML3X Matrix Calculator for interactive step-by-step solutions.