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 vectorecontaining the eigenvalues of the square matrixA.[V,D] = eig(A): Returns matrixVwhose columns are eigenvectors and diagonal matrixDwith 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;
eigreturns 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
Amust 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.