# eig

Eigenvalues and eigenvectors of symbolic matrix

## Syntax

``lambda = eig(A)``
``[V,D] = eig(A)``
``[V,D,P] = eig(A)``
``lambda = eig(B)``
``[V,D] = eig(B)``

## Description

example

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

example

````[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)```.```

example

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

## 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 eigenvalues and eigenvectors for one of the MATLAB® test matrices.

`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,lambda] = eig(A)`
```v =  $\left(\begin{array}{c}0\\ \frac{21}{256}\\ -\frac{71}{128}\\ \frac{973}{256}\\ 1\end{array}\right)$```
```lambda =  $\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)$```

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

## Limitations

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.

## Compatibility Considerations

expand all

Behavior changed in R2021b