Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical & Research SuppliesReagents, PPE & instruments — chain-of-custody documented.Fast, traceable sourcing built for regulated research environments, from bench consumables to instrumentation.Shop lac.us CodeCASRAIlac.us

Eigenvalue in MATLAB: eig, eigs and Eigenvectors

How to compute eigenvalues and eigenvectors in MATLAB with eig and eigs, verify the residual, sort results and compare free alternatives.

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)

  1. Create a square matrix, for example A = gallery("lehmer",4);
  2. 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)

  1. Run [V,D] = eig(A). With two outputs, D is a diagonal matrix of eigenvalues and each column of V is the matching right eigenvector.
  2. Optional: [V,D,W] = eig(A) also returns left eigenvectors in W, satisfying W'*A = D*W'.
  3. 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 residual A*V - V*D on the order of 1e-14. That is floating-point round-off, not an error.
  • Eigenvalues are not sorted. For magic(5), D is 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*D rather 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: eig takes a square matrix; check size(A).
  • Eigenvalues appear in a different order than a textbook or another tool: expected, since eig output 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 the eig page 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

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Eigenvalue in MATLAB: eig, eigs and Eigenvectors

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →