Eigenvalues and Eigenvectors in MATLAB | MATLAB Tutorial


Eigenvalues and Eigenvectors in MATLAB

Set of linear algebraic equations of the general form


Such systems are called nonhomogeneous because of the presence of the vector {b} on the right-hand side of the equality. If the equations comprising such a system are linearly independent (i.e., have a nonzero determinant), they will have a unique solution.

In contrast, a homogeneous linear algebraic system has a right-hand side equal to zero:


At face value, this equation suggests that the only possible solution would be the trivial case for which all x’s = 0. Graphically this would correspond to two straight lines that intersected at zero.

Although this is certainly true, eigenvalue problems associated with engineering are typically of the general form

where the parameter λ is the eigenvalue. Thus, rather than setting the x’s to zero, we can determine the value of λ that drives the left-hand side to zero! One way to accomplish this is based on the fact that, for nontrivial solutions to be possible, the determinant of the matrix must equal zero:

Expanding the determinant yields a polynomial in λ, which is called the characteristic polynomial. The roots of this polynomial are the solutions for the eigenvalues. In order to better understand these concepts, it is useful to examine the two-equation case,

Expanding the determinant of the coefficient matrix gives

which is the characteristic polynomial.


The quadratic formula can then be used to solve for the two eigenvalues:

This approach is called the polynomial method.

Problem 1: Use the polynomial method to solve for the eigenvalues of the following homogeneous system:

Before determining the correct solution, let’s first investigate the case where we have an incorrect eigenvalue. For example, if λ = 3, the equations become

Plotting these equations yields two straight lines that intersect at the origin (Fig. 1a). Thus, the only solution is the trivial case where x1 = x2 = 0.

To determine the correct eigenvalues, we can expand the determinant to give the characteristic polynomial:

which can be solved for

Therefore, the eigenvalues for this system are 15 and 5.

We can now substitute either of these values back into the system and examine the result. For λ1= 15, we obtain

Thus, a correct eigenvalue makes the two equations identical (Fig. 1b). In essence as we move towards a correct eigenvalue the two lines rotate until they lie on top of each other. Mathematically, this means that there are an infinite number of solutions. But solving either of the equations yields the interesting result that all the solutions have the property that x1 = –x2. Although at first glance this might appear trivial, it’s actually quite interesting as it tells us that the ratio of the unknowns is a constant. This result can be expressed in vector form as

which is referred to as the eigenvector corresponding to the eigenvalue λ = 15.

In a similar fashion, substituting the second eigenvalue, λ2 = 5, gives

Again, the eigenvalue makes the two equations identical (Fig. 1b) and we can see that the solution for this case corresponds to x1 = x2, and the eigenvector is

Figure 1: Plots of a system of two homogeneous linear equations from Problem 1. (a) An incorrect eigenvalue (λ = 3) means that the two equations, which are labeled as Eq. 1 and 2 in the figure, plot as separate lines and the only solution is the trivial case (x1 = x2 = 0). (b) In contrast, the cases with correct eigenvalues (λ = 5 and 15), the equations fall on top of each other.

Matlab m-file:

 function [eval,evec] = eigen(A)

 % input:

 % A = coefficient matrix

 % output:

 % eval = eigen value

 % evec = eigen vector

 format short

 [V,~] = eig(A);

 eval = eig(A);

 evec = V;

 evec = round(evec);

 for i = 1:length(evec)

 if evec(:,i) == -1

 evec(:,i) = 1;



 for i = 1:length(eval)

 fprintf('For Eigenvalue = %.4f,\n ', eval(i));

 fprintf('Eigenvector = \n');



The M-file can be used to solve the problem 1.

>> A = [10 -5;-5 10];

>> eigen(A);

For Eigenvalue = 5.0000,

Eigenvector =



For Eigenvalue = 15.0000,

Eigenvector =



I am a Certified MATLAB Associate. I love MATLAB Coding & Enjoy Programming. I can make anything & everything possible with MATLAB.