Matrix computation
Linear Algebra: Matrices, Factorizations and Solving Systems

Most numerical problems end up as a matrix problem. A set of equations becomes Ax = b, a fit to measurements becomes a least squares problem, and the vibration modes of a structure become eigenvalues. The pages in this section show how the standard tools work and, more usefully, how to check their answers by hand on matrices small enough to fit in a notebook.
Solving and factoring
The workhorse is the factorization. Instead of inverting a matrix, a program splits it into triangular or orthogonal pieces that are easy to solve with. LU factorization writes a square matrix as a lower triangular times an upper triangular factor, after row exchanges for stability. Once the split exists, each new right-hand side costs only two triangular solves. The one-off cost of the split grows with the cube of the matrix size, roughly two thirds of n³ operations, which is why reuse matters.
Explicit inverses are almost never needed. Writing x = A⁻¹b invites both extra work and extra rounding error, so numerical code expresses the same thing as a division, a solve with the factors. The page on left matrix division and least squares shows that one operator covers square systems, where it solves exactly, and tall systems, where it returns the least squares fit.
Three other factorizations cover the cases LU does not. When the matrix is symmetric and positive definite, Cholesky factorization gives A = LLᵀ at half the cost and doubles as a definiteness test. For tall problems and least squares, QR factorization builds orthonormal columns and avoids the squared conditioning of normal equations. And the singular value decomposition handles rank, conditioning and low-rank approximation for any matrix at all, at a higher price.
Eigenvalues and their relatives
Eigenvalue problems ask for the directions a matrix only stretches. The Schur factorization is the stable route to all of them: every square matrix can be rotated into an upper triangular form whose diagonal holds the eigenvalues. Pencils of two matrices, as in vibration problems with mass and stiffness, lead to generalized eigenvalues. A neighboring task is finding a clean coordinate system for the columns of a matrix, an orthonormal basis for the range, treated on the orthonormal basis page.
Where to start
A reader who is new to the field should take the pages in this order. First the elementwise basics: what the elements of a matrix are and how elementwise and matrix multiplication differ, a distinction that causes many beginner bugs. Then division and least squares, then LU. Eigenvalues come last, since they use everything before them.
Two habits pay off across the whole section. Test each method on a matrix whose answer is known, such as a diagonal or triangular one. And compare the residual, the size of Ax − b, instead of comparing the solution to a guess, because a small residual is the only evidence a solver can give about its own result. Terminology is collected in the glossary.
The sibling sections build on this one. Optimization relies on the same pivoting and factorization ideas, and signal processing treats the Fourier transform as a matrix with a very special structure.
Questions about linear algebra
Why do programs avoid computing the inverse of a matrix?
Forming A⁻¹ costs several times more than solving one system, and it usually gives a less accurate answer. A factorization such as LU solves Ax = b directly, and the factors can be reused for further right-hand sides. An explicit inverse is only worth computing when its individual entries are the actual result of interest.
What is the difference between a symmetric and a positive definite matrix?
Symmetric means the matrix equals its transpose. Positive definite is stronger: xᵀAx must be positive for every nonzero vector x, which is the same as all eigenvalues being positive. A symmetric matrix can have negative eigenvalues, and then it is not positive definite, so Cholesky factorization fails on it.
When is a matrix singular?
A square matrix is singular when its determinant is zero, which means its columns are linearly dependent and Ax = b has either no solution or infinitely many. Numerically, nearly singular matrices matter just as much: a very large condition number warns that small errors in the data can produce large errors in the answer.
What does the residual of a linear solve tell me?
The residual is Ax − b for the computed x. A small residual shows that x nearly satisfies the equations, which is the strongest check a solver can offer on its own work. It does not guarantee a small error in x itself when the matrix is badly conditioned, so look at both.
Benchmarking Numerical Code: Methods and Mistakes
Trustworthy benchmarks warm up, repeat, report a robust statistic, vary problem size and state the environment.
Cholesky Factorization: A = LLᵀ Method and Worked Example
Cholesky factorization splits a symmetric positive definite matrix into a triangular factor and its transpose, at half the cost of LU.
Complex Conjugate of Numbers, Vectors and Matrices
The complex conjugate of a + bi is a − bi; applied entrywise and combined with a transpose it gives the Hermitian adjoint.
Cumulative Product (cumprod) of a Vector or Matrix
The cumulative product returns every running product of a vector or of each matrix column; factorials and compound growth are typical uses.
Element-by-Element Multiplication of Matrices
Element-by-element multiplication multiplies matching entries of two arrays; it is a different operation from the matrix product.
Elements of a Matrix: Subscripts, Slices and Linear Indices
Each element of a matrix is named by a row and column index; slices and linear indices select whole groups of elements at once.
Generalized Eigenvalues and Eigenvectors: Ax = λBx
Generalized eigenvalues are the scalars λ for which Ax = λBx has a nonzero solution x; B = I recovers the ordinary problem.
GPU Computing for MATLAB-Style Matrix Code
GPU acceleration pays off for large, arithmetic-heavy array operations; transfer cost and memory limits decide the rest.
Left Matrix Division and Linear Least Squares
For rectangular A, left division returns the vector minimizing ‖Ax − b‖, the linear least squares solution.
LU Factorization of a Matrix: Method and Worked Example
LU factorization splits a square matrix into lower and upper triangular factors, turning a linear solve into two cheap substitutions.
MATLAB Matrix Functions and Their Equivalents in Other Languages
A practical map from MATLAB matrix functions to Octave, NumPy, Julia and Scilab, including the places where behavior, not just spelling, differs.
MATLAB-Style Matrix Languages Compared
MATLAB, GNU Octave, NumPy, Julia and Scilab share a core of array operations and differ in syntax, indexing, licensing and ecosystem.
Matrix Division: Solving Ax = b and xA = b
Matrix division is shorthand for solving linear systems; left division solves Ax = b, right division solves xA = b.
Orthonormal Basis for the Range (Column Space) of a Matrix
An orthonormal basis for the range of A is a set of perpendicular unit vectors spanning every product Ax; SVD or QR produce one.
QR Factorization: Gram–Schmidt, Householder and Least Squares
QR factorization builds orthonormal columns from a matrix, giving a stable route to least squares and orthonormal bases.
Schur Factorization: The Schur Form of a Matrix
The Schur factorization A = QTQᴴ triangularizes any square matrix with an orthogonal or unitary change of basis, exposing its eigenvalues.
Singular Value Decomposition: Rank, Condition and Approximation
The SVD factors any matrix into two rotations and a diagonal scaling, revealing rank, conditioning and the best low-rank approximation.
What Is a Matrix Language? Arrays, Operators and Vectorization
A matrix language makes the array its basic value, with operators for linear algebra and whole-array arithmetic instead of explicit loops.
Working at a Matrix Command Prompt: Entering Code and Reading Results
A matrix command prompt evaluates one statement at a time against a workspace of named arrays; scripts and functions grow out of it.