Introduction to MATLAB Eigenvalues
Aneigenvalue is a special set of scalar factors which changes the eigenvector or characteristic vector of a linear transformation and gets associated with a linear system of equations or to a matrix. The eigenvalue approach is to find out the solution to an equation in the form of:
Mv = λv
Where M is an nbyn input matrix, ‘v’ is a column vector having a length of size ‘n’, and λ is a scalar factor. The values corresponding to λ that satisfy the equation specified in the above form, are counted as eigenvalues. The values of v corresponding to that satisfy the equation are counted as the right eigenvectors.
Syntax
Below awe will understand the syntax with description:
Syntax  Description 
e = eig(M)  It results in a column vector consisting of the eigenvalues with respect to the square matrix M. 
[E_{R},M_{D}] = eig(M)  It results ina diagonal matrix M_{D} of eigenvalues and matrix V whose columns are the corresponding right eigenvectors, so that M*V = V*M. 
[E_{L},M_{D},M_{F}] = eig(M)  It results in full matrix M_{F}whose columns are the corresponding left eigenvectors, so that M_{F}‘*M = M_{D}* M_{F}‘. 
e = eig(P,Q)  It results in a column vector that contains the generalized eigenvalues of square matrices P and Q. 
[E_{R}, M_{D}] = eig(P,Q)  It results in diagonal matrix M_{D} of generalized eigenvalues and full matrix V whose columns are the corresponding right eigenvectors, so that M*V = Q*V* M_{D}. 
[E_{L},D, M_{F}] = eig(P,Q)  It results in full matrix M_{F} whose columns are the corresponding left eigenvectors so that M_{F}‘*P = D*M_{F}‘*Q. 
[___] = eig(M,balanceOption)  It results in using the balanceOptionparameter is to decide on enabling or disabling of the preliminary balancing step in the algorithm while solving Eigenvalues for the matrix M. 
[___] = eig(P,Q,algorithm)  The parameter ‘algorithm’ decides on how the Eigenvalues will be computed depending on the properties of P and Q.
Example:

[___] = eig(___,eigvalOption)  It results in the eigenvalues in the form which is specified as eigvalOption. 
Note:
1. If the parameter ‘algorithm’ is excluded from the command, the functioneigchoosesthe algorithm depending on the properties of P and Q.
By default, the selected algorithm is ‘chol’. This algorithm also supports solving the eigenvalue problem where matrix ‘P’ is symmetric (Hermitian) and ‘Q’ is symmetric (Hermitian) positive definite.
2. Irrespective of the algorithm being specified, eig() function always applies the QZ algorithm where P or Q is not symmetric.
3. The eigenvalue option supports two values as ‘vector’ or ‘matrix’ that decides the form of Eigenvalues is a column vector or a diagonal matrix. The behavior also depends on the number of outputs being specified.
 Case1: Single output, i.e e = eig(M), then the return form of eigenvalues is a column vector.
 Case2: multiple outputs, such as [V,D] = eig(M), then the return form ofeigenvalues is a diagonal matrix, D.
How do Eigenvalue works?
As we have discussed earlier, eigenvalue(s) for a given input matrix ‘M’ satisfies the equation of :
 M·v=λ·v
Where v is an nby1 nonzero vector and λ is a scalar factor. The set of values that can replace for λ and the above equation results a solution, is the set of eigenvalues or characteristic values for the matrix M. The vector corresponding to an Eigenvalue is called an eigenvector.
The eigenvalue equation can also be stated as:
 M·vλ·v=0
 M·vλ·I·v=0
 (Mλ·I)·v=0
When v is non zero vector then the equation will have a solution only when
 Mλ·I=0
The above equation is coined as the characteristic equation of the input matrix ‘M’, and which is a nth order polynomial in λ with n roots. These roots are called the eigenvalues of A. We will only deal with the case of n distinct roots, though they may be repeated.
Thus Eigenvectors are generated with respect to each eigenvalue for which the eigenvalue equation mentioned above is true.
Example #1
Code:
M = gallery('lehmer',5)
e = eig(M)
Output:
Example #2
The below code snippet solves the Eigenvalues resulting right Eigenvector.
Code:
M = gallery('circul',3)
[Er,D] = eig(M)
Output:
Sorted Eigenvalues and Eigenvectors
The functionsort() can be used to arrange the eigenvalues in ascending order accordingly to the corresponding Eigenvectors as well.
Example
The below set of command solves the eigenvalue for the given input matrix ‘M’ and rearrange the resultant matrix in ascending order.
Code:
M= magic(5)
[Er,D_sorted] = eig(M)
[dm,ind] = sort(diag(D_sorted))
D_sorted = D_sorted(ind,ind)
Er_sorted = Er(:,ind)
Output:
LeftEigenvectors
Left eigenvector is nothing but the eigenvector derived where the column vector that satisfies the eigenvalue equation is placed in the left side if the input matrix.
 v.M = λ·v
Example
Code:
M = [10 17 23; 32 19 12; 25 22 17];
[El,D,Mf] = eig(M);
Mf'*M  D*Mf'
Output:
Eigenvalues of Defective or Nondiagonalizable matrix
When the input matrix has repeated eigenvalues and the eigenvectors are dependent by nature, then the input matrix is said to be a not diagonalizable and is, thus marked as defective.
In this case, eigenvalue decomposition does not satisfy the equation exactly.
3 Online Courses  1 Handson Project 8+ Hours Verifiable Certificate of Completion
4.5
View Course
Code:
M = [30 10 0; 0 30 10; 0 0 30];
[Er,D] = eig(M);
M*Er  Er*D
Output:
The difference between M*Er andEr*D is not exactly zero.
Calculating Eigenvalue for Singular Matrix
If the matrices P and Q result in (P/Q)=Inf, it is recommended to calculate the eigenvalues for both matrices separately.
Code
P = eye(2);Q = [3 6; 4 8];[V,D] = eig(P)[V,D] = eig(Q)
Output:
Additional Note:
 Though both the algorithms produce similar results, the QZ algorithm happens to be more stable for certain systems such as in case of badly conditioned matrices.
 The eig function also supports calculating eigenvalues of sparse matrices which are real and symmetric by nature. In order to calculate the eigenvectors and Eigenvectors of a sparse matrix, which is not real and symmetric, the functioneigs() can be used.
Recommended Articles
This is a guide to MATLAB Eigenvalues. Here we discuss an introduction to MATLAB Eigenvalues, how Eigenvalues work in Matlab, how to calculate, Eigenvalues in detail. You can also go through our other related articles to learn more –