MATLAB - Eigenvalues and Eigenvectors



Eigenvalues and eigenvectors are fundamental concepts in linear algebra, widely used in various fields, including physics, engineering, and data analysis. In MATLAB, these concepts can be explored and computed easily.

What is EigenValues?

An eigenvalue is a scalar, denoted as (lambda), associated with a linear transformation of a vector space. It represents the factor by which the corresponding eigenvector is scaled during the transformation.

What is EigenVectors?

An eigenvector is a non-zero vector that only changes by a scalar factor when a linear transformation is applied to it. In other words, if A is a matrix, v is an eigenvector of A corresponding to the eigenvalue if −

Av=v

Here, A is a square matrix, v is the eigenvector, and is the eigenvalue.

MATLAB Functions

MATLAB provides built-in functions to compute eigenvalues and eigenvectors.

Using eig

This function computes the eigenvalues and eigenvectors of a matrix.

Syntax

e = eig(A)
[V,D] = eig(A)
[V,D,W] = eig(A)
e = eig(A,B)
[V,D] = eig(A,B)
[V,D,W] = eig(A,B)
[___] = eig(A,balanceOption)
[___] = eig(A,B,algorithm)
[___] = eig(___,outputForm)

Explanation of Syntax

e = eig(A) returns a column vector with the eigenvalues of the square matrix A.

[V,D] = eig(A) returns a diagonal matrix D with the eigenvalues of A and a matrix V whose columns are the corresponding eigenvectors. This means that multiplying A by V is the same as multiplying V by D.

[V,D,W] = eig(A) also returns a full matrix W whose columns are the corresponding left eigenvectors. This means that multiplying the transpose of W by A is the same as multiplying D by the transpose of W.

The eigenvalue problem is about finding solutions to the equation Av = v, where A is a square matrix, v is a column vector, and is a scalar. The values that satisfy this equation are the eigenvalues, and the v values that satisfy it are the right eigenvectors. The left eigenvectors, w, satisfy the equation w'A = w'.

e = eig(A,B) returns a column vector with the generalized eigenvalues of the square matrices A and B.

[V,D] = eig(A,B) returns a diagonal matrix D with the generalized eigenvalues and a full matrix V whose columns are the corresponding right eigenvectors. This means that multiplying A by V is the same as multiplying B, V, and D together.

[V,D,W] = eig(A,B) also returns a full matrix W whose columns are the corresponding left eigenvectors. This means that multiplying the transpose of W by A is the same as multiplying D, the transpose of W, and B.

The generalized eigenvalue problem is about finding solutions to the equation Av = Bv, where A and B are square matrices, v is a column vector, and is a scalar. The values that satisfy this equation are the generalized eigenvalues, and the v values are the corresponding right eigenvectors. The left eigenvectors, w, satisfy the equation w'A = w'B.

[___] = eig(A, balanceOption), where balanceOption is "nobalance", turns off the preliminary balancing step in the algorithm. By default, balanceOption is "balance", which turns balancing on. The eig function can return any of the output arguments mentioned in the previous examples.

[___] = eig(A,B,algorithm), where algorithm is "chol", uses the Cholesky factorization of B to compute the generalized eigenvalues. The default algorithm depends on the properties of A and B, but it is "qz" (QZ algorithm) when A or B are not symmetric.

[___] = eig(___,outputForm) returns the eigenvalues in the format specified by outputForm, using any of the input or output arguments mentioned earlier. Set outputForm to "vector" to get the eigenvalues in a column vector, or "matrix" to get them in a diagonal matrix.

Examples for Matlab Function eig()

Here are some examples to illustrate how to use it −

Example 1: To calculate eigenvalues using e = eig(A)

In MATLAB, you can find the eigenvalues of matrix A using the eig function. Consider the following code −

% Define the matrix A
A = [1, 2, 3;
     4, 5, 6;
     7, 8, 9];

% Compute the eigenvalues
e = eig(A)

In the above example −

  • The matrix A is defined as a 3x3 matrix with entries as shown.
  • The eig(A) function computes the eigenvalues of matrix A.
  • The result of eig(A) is stored in the variable e, which is a column vector containing the eigenvalues of A.

When the code is computed the output we get is as follows −

>> % Define the matrix A
A = [1, 2, 3;
     4, 5, 6;
     7, 8, 9];

% Compute the eigenvalues
e = eig(A)


e =

   16.1168
   -1.1168
   -0.0000

Example 2: To get eigenValues and eigenVectors using [V,D] = eig(A)

In MATLAB, you can find the eigenvalues and eigenvectors of matrix A using the eig function.

Consider following code −

% Define the matrix A
A = [2, -1;
     4, 3];

% Compute the eigenvalues and eigenvectors
[V, D] = eig(A);

% Display the eigenvalues
disp('Eigenvalues:');
disp(D);

% Display the eigenvectors
disp('Eigenvectors:');
disp(V);

In above code we have −

  • The matrix A is defined as a 2x2 matrix with entries as shown.
  • The [V, D] = eig(A) function computes both the eigenvalues (D) and the corresponding eigenvectors (V) of matrix A.
  • D is a diagonal matrix containing the eigenvalues of A.
  • V is a matrix whose columns are the corresponding eigenvectors.

When the code is executed the output we get is as follows −

>> % Define the matrix A
A = [2, -1;
     4, 3];

% Compute the eigenvalues and eigenvectors
[V, D] = eig(A);

% Display the eigenvalues
disp('Eigenvalues:');
disp(D);

% Display the eigenvectors
disp('Eigenvectors:');
disp(V);

Eigenvalues:
   2.5000 + 1.9365i   0.0000 + 0.0000i
   0.0000 + 0.0000i   2.5000 - 1.9365i

Eigenvectors:
  -0.1118 + 0.4330i  -0.1118 - 0.4330i
   0.8944 + 0.0000i   0.8944 + 0.0000i
Advertisements