Matlab

How to Find Eigenvalues and Eigenvectors in MATLAB Using eig() Function?

MATLAB is a beneficial tool for solving mathematical problems like matrix operations. It has various built-in functions for solving these problems. One of the well-known matrix operations is eigenvalues and eigenvectors. For calculating eigenvalues and their corresponding eigenvectors of a square matrix, MATLAB provides a built-in eig() function.

The main objective of this guide is to explain how to find eigenvalues as well as eigenvectors in MATLAB by using the eig() function.

What are Eigenvalues and Eigenvectors?

Before moving toward how to find eigenvalues and eigenvectors in MATLAB, let’s first define what eigenvalues and eigenvectors are.

Eigenvalues are unique values that have a special meaning when it comes to matrices. They reveal how a matrix affects different directions or vectors when it is multiplied by them. While Eigenvectors are the corresponding special vectors that do not change their direction, instead change their size when multiply by the matrix. When both eigenvalues and eigenvectors are combined, they provide valuable information about the behavior and characteristics of a matrix.

Let A be any square matrix of size n, V be any vector of size n-by-1, and x be any scalar value then V is called an eigenvector, and x is called an eigenvalue of A if they satisfied the given equation:

A*V = x*V

A square matrix of size n can have n eigenvectors corresponding to their eigenvalues.

How to Calculate the Eigenvalues and Eigenvectors in MATLAB Using eig() Function?

The eig() is a built-in function in MATLAB that enables us to compute eigenvalues and their corresponding eigenvectors of a given matrix A. This function accepts one or more matrices as inputs and returns their eigenvalues and eigenvectors.

Syntax
The eig() function follows a simple syntax in MATLAB:

e = eig(A)
[V,D] = eig(A)

Here:

The function e = eig(A) provides a column vector having eigenvalues of the given matrix A.

The function [V, D] = eig(A) provides a diagonal matrix D containing eigenvalues of the given matrix A as its diagonal entries and it also returns a matrix V that has eigenvectors corresponding to eigenvalues as its columns.

Examples

Consider some examples to understand how to find eigenvalues and eigenvectors in MATLAB using the eig() function.

Example 1: Use eig() Function to Calculate Eigenvalues of Matrix

In this example, we first create a square matrix of size 4 using the magic() function and then use the eig() function to calculate the eigenvalues of the matrix A stored in the column vector X.

A = magic(4)
X = eig(A)

Example 2: Use the eig() Function to Calculate Eigenvalues and Eigenvectors of the Square Matrix

This MATLAB code first creates a square matrix using the magic() function and then calculates its eigenvalues and eigenvectors using the function [V, D] = eig(A).

A = magic(4)
[X, e] = eig(A)

In the above output, the X shows eigenvectors while e is showing eigenvalues of matrix A.

Conclusion

The eigenvalues and eigenvectors are important concepts used in mathematics and engineering. Any square matrix of size n can have n eigenvalues and their corresponding eigenvectors. MATLAB provides us with a built-in eig() function that finds the eigenvalues and eigenvectors of the given square matrix A. This guide has discussed the easy way to find the eigenvalues and eigenvectors of the given matrix in MATLAB using the eig() function.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.