Main Content


Eigenvalues and eigenvectors of symbolic matrix



lambda = eig(A) returns a symbolic vector containing the eigenvalues of the square symbolic matrix A.


[V,D] = eig(A) returns matrices V and D. The columns of V present eigenvectors of A. The diagonal matrix D contains eigenvalues. If the resulting V has the same size as A, then the matrix A has a full set of linearly independent eigenvectors that satisfy A*V = V*D.

[V,D,P] = eig(A) returns a vector of indices P. The length of P is equal to the number of linearly independent eigenvectors, so that A*V = V*D(P,P).


lambda = eig(B) returns numeric eigenvalues of the square variable-precision matrix B. To convert a symbolic matrix A to variable-precision, use B = vpa(A).

[V,D] = eig(B) also returns numeric eigenvectors.


collapse all

Compute eigenvalues for the magic square of order 5.

A = sym(magic(5));
lambda = eig(A)
lambda = 


Compute numeric eigenvalues for the magic square of order 5 using variable-precision arithmetic.

A = magic(5);
lambda = eig(vpa(A))
lambda = 


Create a 5-by-5 symbolic matrix from the magic square of order 6. Compute the eigenvalues of the matrix using eig.

M = magic(6);
A = sym(M(1:5,1:5));
lambda = eig(A)
lambda = 

(root(σ1,z,1)root(σ1,z,2)root(σ1,z,3)root(σ1,z,4)root(σ1,z,5))where  σ1=z5-100z4+134z3+66537z2-450198z-1294704

The eig function cannot find the exact eigenvalues in terms of symbolic numbers. Instead, it returns them in terms of the root function.

Use vpa to numerically approximate the eigenvalues.

lambdaVpa = vpa(lambda)
lambdaVpa = 


Compute the eigenvalues and eigenvectors for one of the MATLAB® test matrices.

A = sym(gallery(5))
A = 


[v,lambda] = eig(A)
v = 


lambda = 


Input Arguments

collapse all

Square matrix, specified as a symbolic matrix.

Square variable-precision matrix, specified as a numeric matrix. To convert a symbolic matrix A to variable-precision, use B = vpa(A).

Output Arguments

collapse all

Eigenvalues, returned as a symbolic column vector or column vector of symbolic numbers.

Right eigenvectors, returned as a square symbolic matrix whose columns are the right eigenvectors of A.

Eigenvalues, returned as a symbolic diagonal matrix with the eigenvalues of A on the main diagonal.

Vector of indices, returned as a symbolic row vector whose length is the total number of linearly independent eigenvectors.


Matrix computations involving many symbolic variables can be slow. To increase the computational speed, reduce the number of symbolic variables by substituting the given values for some variables.

Version History

Introduced before R2006a

expand all

Behavior changed in R2021b

See Also

| | |