Written and maintained by CASRAI Editorial Board
Last updated
Short answer: in MATLAB, e = eig(A) returns the eigenvalues of a square matrix A as a column vector, and [V,D] = eig(A) returns the eigenvectors in the columns of V and the eigenvalues on the diagonal of D, so that A*V = V*D. For large sparse matrices where you need only a few eigenvalues, use eigs instead. This guide is for researchers and analysts who need to compute, check and interpret eigenvalues in MATLAB; it follows the MathWorks reference pages for eig and eigs (read 2026-11-07).
What eigenvalues are used for in research
Eigenvalues and eigenvectors appear wherever a linear system is analysed: principal components of a covariance matrix, vibration modes and stability of dynamical systems, and Markov or population-matrix models. This page covers the MATLAB mechanics (which function, which call form, how to read and verify the output); it does not teach the underlying linear algebra.
Install or access (official source only)
eig and eigs are documented in the MATLAB reference at mathworks.com/help/matlab. Obtain and activate MATLAB through MathWorks as described in the MATLAB installation guide. If you also need to build the matrix first, see matrices in MATLAB.
Step by step: eigenvalues in MATLAB
1. Eigenvalues only: matlab eigenvalues with eig(A)
- Create a square matrix, for example
A = gallery("lehmer",4); - Run
e = eig(A). With one output, MATLAB returns a column vector. For this Lehmer matrix the documentation lists eigenvalues of about 0.2078, 0.4078, 0.8482 and 2.5362.
2. Eigenvectors and eigenvalues in MATLAB: [V,D] = eig(A)
- Run
[V,D] = eig(A). With two outputs,Dis a diagonal matrix of eigenvalues and each column ofVis the matching right eigenvector. - Optional:
[V,D,W] = eig(A)also returns left eigenvectors inW, satisfyingW'*A = D*W'. - Optional: add
"vector"or"matrix"as the last argument to choose the output form of the eigenvalues ([V,d] = eig(A,"vector")).
3. Generalized problem: eig(A,B)
For A*v = λ*B*v, call e = eig(A,B) or [V,D] = eig(A,B). The algorithm argument selects "chol" (default for the symmetric case) or "qz". When B is singular, eig(A,B) still returns a result: the documentation’s example with A = eye(2) returns one finite eigenvalue (0.0909) and one Inf.
4. Large sparse matrices: eigs
d = eigs(A) returns the six largest-magnitude eigenvalues; eigs(A,k) returns k of them; eigs(A,k,sigma) targets eigenvalues near sigma ("smallestabs" is the same as sigma = 0). [V,D,flag] = eigs(___) adds a convergence flag, where 0 means all requested eigenvalues converged. For a function handle, use eigs(Afun,n,___).
Which function: eig, eig(A,B) or eigs
| Situation | Call | Source note |
|---|---|---|
| All eigenvalues of a standard problem | eig(A) |
Returns all eigenvalues |
| Generalized problem, including singular B | eig(A,B) |
Works when B is singular |
| Sparse, real and symmetric, all eigenvalues | eig(A) |
Documented as supported |
| Sparse eigenvectors, or non-symmetric sparse eigenvalues | eigs |
The eig page directs these cases to eigs |
| A few eigenvalues of a large matrix | eigs(A,k) |
Useful when computing all of them is expensive; for small dense matrices eig(full(A)) may be quicker |
Output and how to read it
- Check the residual. For the circulant matrix
A = gallery("circul",3), the documentation reports eigenvalues 6 and a complex pair near −1.5 ± 0.866i, and a residualA*V - V*Don the order of 1e-14. That is floating-point round-off, not an error. - Eigenvalues are not sorted. For
magic(5),Dis unsorted. Sort and reorder together:[d,ind] = sort(diag(D)); Ds = D(ind,ind); Vs = V(:,ind); - Special matrices. Real symmetric or complex Hermitian input gives real eigenvalues; skew-symmetric or skew-Hermitian input gives purely imaginary ones.
- Eigenvector scaling. Each eigenvector has 2-norm 1 and, for symmetric, Hermitian or skew-Hermitian
A, the vectors are orthonormal. With"nobalance"the norms are not necessarily 1. - Reproducibility. Signs and complex phases of eigenvectors can differ between machines and MATLAB releases, so compare
A*V - V*Drather than raw eigenvector entries.
For related matrix operations, see matrix multiplication in MATLAB and solving equations in MATLAB.
Troubleshooting
- Error that the matrix must be square:
eigtakes a square matrix; checksize(A). - Eigenvalues appear in a different order than a textbook or another tool: expected, since
eigoutput is unordered; sort as shown above. - Tiny nonzero imaginary parts or residuals around 1e-14: round-off, as in the circulant example.
- Sparse input and eigenvectors requested: use
eigs, as theeigpage directs. - Different results with
"nobalance": balancing is on by default; turning it off can change eigenvector norms.
Free alternatives
| Tool | Call | Documented behaviour |
|---|---|---|
| NumPy | numpy.linalg.eig(a) |
Returns eigenvalues and unit-length eigenvectors (columns); eigenvalues not necessarily ordered; docs recommend eigh for symmetric or Hermitian input |
| GNU Octave | [V, lambda] = eig(A) |
Same call forms as MATLAB, including eig(A, B); eigenvalues are not ordered |
| R (base) | eigen(x) |
Returns a list with values and vectors; values sorted by decreasing modulus for asymmetric matrices; vectors normalized to unit length |
Note the difference: R sorts for asymmetric matrices, while MATLAB, NumPy and Octave do not guarantee any order.
FAQ
How do I find eigenvalues in MATLAB?
Use e = eig(A) for a square matrix A; the result is a column vector of eigenvalues.
How do I get eigenvectors as well as eigenvalues in MATLAB?
Use [V,D] = eig(A). Columns of V are eigenvectors and the diagonal of D holds the eigenvalues, with A*V = V*D.
Does eig sort eigenvalues?
No. The documentation’s magic(5) example returns D unsorted; sort diag(D) and reorder the columns of V to match.
When should I use eigs instead of eig?
For large sparse matrices when you need only some eigenvalues, or for eigenvectors of sparse matrices and eigenvalues of non-symmetric sparse matrices.
Sources
- MathWorks, eig: Eigenvalues and eigenvectors, read 2026-11-07.
- MathWorks, eigs: Subset of eigenvalues and eigenvectors, read 2026-11-07.
- NumPy, numpy.linalg.eig, read 2026-11-07.
- GNU Octave documentation, Basic Matrix Functions, read 2026-11-07.
- R documentation, eigen, read 2026-11-07.







