0
0
MatlabHow-ToBeginner ยท 3 min read

How to Find Eigenvalues in MATLAB: Simple Guide

In MATLAB, you can find eigenvalues of a matrix using the eig function. Simply pass your square matrix to eig, and it returns a vector of eigenvalues.
๐Ÿ“

Syntax

The basic syntax to find eigenvalues is:

  • e = eig(A): Returns a column vector e containing the eigenvalues of the square matrix A.
  • [V,D] = eig(A): Returns matrix V whose columns are eigenvectors and diagonal matrix D with eigenvalues on the diagonal.
matlab
e = eig(A);
[V,D] = eig(A);
๐Ÿ’ป

Example

This example shows how to find eigenvalues of a 2x2 matrix and display them.

matlab
A = [4 2; 1 3];
e = eig(A);
disp('Eigenvalues:');
disp(e);
Output
Eigenvalues: 5.0000 2.0000
โš ๏ธ

Common Pitfalls

Common mistakes include:

  • Passing a non-square matrix to eig, which causes an error.
  • Confusing eigenvalues with eigenvectors; eig returns eigenvalues by default unless you request eigenvectors.
  • Not handling complex eigenvalues properly when the matrix is not symmetric.
matlab
A = [1 2 3; 4 5 6]; % Non-square matrix
% Wrong usage:
e = eig(A); % This will cause an error

% Correct usage:
A = [1 2; 3 4];
e = eig(A);
Output
Error using eig Matrix must be square.
๐Ÿ“Š

Quick Reference

Remember these tips when finding eigenvalues in MATLAB:

  • Use eig(A) for eigenvalues only.
  • Use [V,D] = eig(A) to get eigenvectors and eigenvalues.
  • Matrix A must be square.
  • Eigenvalues can be complex numbers.
โœ…

Key Takeaways

Use the eig function to find eigenvalues of a square matrix in MATLAB.
Pass your matrix as eig(A) to get eigenvalues as a vector.
Request eigenvectors with [V,D] = eig(A) if needed.
Ensure the matrix is square to avoid errors.
Eigenvalues may be complex if the matrix is not symmetric.