# eig

Eigenvalues and eigenvectors of symbolic matrix

## Description

example

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

example

[V,D] = eig(A) returns the eigenvectors and eigenvalues of A as symbolic matrices V and D. The columns of V present eigenvectors of A. The main diagonal of D present eigenvalues of A.

• If V is the same size as A, then the matrix A has a full set of linearly independent eigenvectors that satisfy A*V = V*D.

• If V has fewer columns than A, then the matrix A is defective. In this case, at least one of the eigenvalues λ has an algebraic multiplicity m > 1 with fewer than m linearly independent eigenvectors associated with λ.

example

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

## Examples

collapse all

Compute eigenvalues for the magic square of order 5.

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

$\left(\begin{array}{c}65\\ \sqrt{\frac{625}{2}-\frac{5 \sqrt{3145}}{2}}\\ \sqrt{\frac{5 \sqrt{3145}}{2}+\frac{625}{2}}\\ -\sqrt{\frac{625}{2}-\frac{5 \sqrt{3145}}{2}}\\ -\sqrt{\frac{5 \sqrt{3145}}{2}+\frac{625}{2}}\end{array}\right)$

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

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

$\left(\begin{array}{c}65.0\\ 21.276765471473795530626426697974\\ 13.126280930709218802525643085949\\ -13.126280930709218802525643085949\\ -21.276765471473795530626426697974\end{array}\right)$

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 =

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 =

$\left(\begin{array}{c}-2.181032364984695108354692701065\\ 9.8395828502812312578803604206392\\ -25.131641669799891607267584639192\\ 26.341617610275869035465716505806\\ 91.131473574227486422276200413812\end{array}\right)$

Compute the exact eigenvalues and eigenvectors for one of the MATLAB® test matrices that is defective.

A = sym(gallery(5))
A =

$\left(\begin{array}{ccccc}-9& 11& -21& 63& -252\\ 70& -69& 141& -421& 1684\\ -575& 575& -1149& 3451& -13801\\ 3891& -3891& 7782& -23345& 93365\\ 1024& -1024& 2048& -6144& 24572\end{array}\right)$

[V,D] = eig(A)
V =

$\left(\begin{array}{c}0\\ \frac{21}{256}\\ -\frac{71}{128}\\ \frac{973}{256}\\ 1\end{array}\right)$

D =

$\left(\begin{array}{ccccc}0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0\end{array}\right)$

The output V is a 5-by-1 column vector with five-fold eigenvalues of 0. This result means that the matrix A has an eigenvalue of 0 with algebraic multiplicity 5 and geometric multiplicity 1.

Compute the exact eigenvalues and eigenvectors of a 4-by-4 symbolic matrix. Return a vector of indices that relate the eigenvalues to their linearly independent eigenvectors.

syms c
A = [c 1 0 0; 0 c 0 0; 0 0 3*c 0; 0 0 0 3*c];
[V,D,p] = eig(A)
V =

$\left(\begin{array}{ccc}1& 0& 0\\ 0& 0& 0\\ 0& 1& 0\\ 0& 0& 1\end{array}\right)$

D =

$\left(\begin{array}{cccc}c& 0& 0& 0\\ 0& c& 0& 0\\ 0& 0& 3 c& 0\\ 0& 0& 0& 3 c\end{array}\right)$

p = 1×3

1     3     4

The matrix A has two eigenvalues, $\mathit{c}$ and $3\text{\hspace{0.17em}}\mathit{c}$, where each eigenvalue occurs twice. Meanwhile, there are three linearly independent eigenvectors. The vector of indices p shows that:

• p(1) = 1, so the first eigenvector (the first column of V) corresponds to the first diagonal element of D with eigenvalue $\mathit{c}$.

• p(2) = 3, so the second eigenvector (the second column of V) corresponds to the third diagonal element of D with eigenvalue $3\text{\hspace{0.17em}}\mathit{c}$.

• p(3) = 4, so the third eigenvector (the third column of V) corresponds to the fourth diagonal element of D with eigenvalue $3\text{\hspace{0.17em}}\mathit{c}$.

This result means the eigenvalue $\mathit{c}$ that occurs twice has only one linearly independent eigenvector (the eigenvalue $\mathit{c}$ has algebraic multiplicity 2 and geometric multiplicity 1). The eigenvalue $3\text{\hspace{0.17em}}\mathit{c}$ that occurs twice has two linearly independent eigenvectors (the eigenvalue $3\text{\hspace{0.17em}}\mathit{c}$ has algebraic multiplicity 2 and geometric multiplicity 2).

Show that the matrix A*V is equal to V*D(p,p).

A*V
ans =

$\left(\begin{array}{ccc}c& 0& 0\\ 0& 0& 0\\ 0& 3 c& 0\\ 0& 0& 3 c\end{array}\right)$

V*D(p,p)
ans =

$\left(\begin{array}{ccc}c& 0& 0\\ 0& 0& 0\\ 0& 3 c& 0\\ 0& 0& 3 c\end{array}\right)$

tf = isequal(A*V,V*D(p,p))
tf = logical
1

## Input Arguments

collapse all

Square matrix, specified as a symbolic matrix.

## 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. The columns of V are the right eigenvectors of A.

Eigenvalues, returned as a symbolic diagonal matrix. The eigenvalues of A are on the main diagonal of D.

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

## Tips

• 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.

• Calling eig for numeric matrices that are not symbolic objects (not created by sym, syms, or vpa) invokes the MATLAB® eig function.

• The symbolic eig function does not support solving the generalized eigenvalue problem (with two input arguments). To solve the generalized eigenvalue problem, use the MATLAB eig function instead by converting the input matrices to a MATLAB numeric type.

## Version History

Introduced before R2006a

expand all