3. Matlab Functions

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 n-by-n 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.


Below awe will understand the syntax with description:

e = eig(M)It results in a column vector consisting of the eigenvalues with respect to the square matrix M.
[ER,MD] = eig(M)It results ina diagonal matrix MD of eigenvalues and matrix V whose columns are the corresponding right eigenvectors, so that M*V = V*M.
[EL,MD,MF] = eig(M)It results in full matrix MFwhose columns are the corresponding left eigenvectors, so that MF‘*M = MD* MF‘.
e = eig(P,Q)It results in a column vector that contains the generalized eigenvalues of square matrices P and Q.
[ER, MD] = eig(P,Q)It results in diagonal matrix MD of generalized eigenvalues and full matrix V whose columns are the corresponding right eigenvectors, so that M*V = Q*V* MD.
[EL,D, MF] = eig(P,Q)It results in full matrix MF whose columns are the corresponding left eigenvectors so that MF‘*P = D*MF‘*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:‘chol’: the generalized eigenvalues of P and Qare copmutedusing the Cholesky factorization of Q.‘qz’:QZ algorithm is used, which is also known as generalised Schur decomposition. This algorithm works for non-symmetry matrices as well.
[___] = eig(___,eigvalOption)It results in the eigenvalues in the form which is specified as eigvalOption.


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 n-by-1 non-zero 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:


M = gallery('lehmer',5)
e = eig(M)


MATLAB Eigenvalues - 1

Example 2:

The below code snippet solves the Eigenvalues resulting right Eigenvector.


M = gallery('circul',3)
[Er,D] = eig(M)


MATLAB Eigenvalues - 2

Sorted Eigenvalues and Eigenvectors

The functionsort() can be used to arrange the eigenvalues in ascending order accordingly to the corresponding Eigenvectors as well.


The below set of command solves the eigenvalue for the given input matrix ‘M’ and rearrange the resultant matrix in ascending order.


M= magic(5)
[Er,D_sorted] = eig(M)
[dm,ind] = sort(diag(D_sorted))
D_sorted = D_sorted(ind,ind)
Er_sorted = Er(:,ind)


MATLAB Eigenvalues - 3
MATLAB Eigenvalues - 4


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



M = [10 17 23; 32 19 12; 25 22 17];
[El,D,Mf] = eig(M);
Mf'*M - D*Mf'



Eigenvalues of Defective or Non-diagonalizable 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.


M = [30 10 0; 0 30 10; 0 0 30];
[Er,D] = eig(M);
M*Er - Er*D


Non-diagonalizable matrix

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.


P = eye(2);Q = [3 6; 4 8];[V,D] = eig(P)[V,D] = eig(Q)


Singular Matrix

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.


Leave a Reply

Your email address will not be published. Required fields are marked *