'eigs and eig'-- which one should I choose?

49 views (last 30 days)
mingcheng nie
mingcheng nie on 3 Apr 2023
Answered: Vandit on 4 Apr 2023
Hi there,
I have two square matrix G1 and G2, both obtain the same size. Now, I want to obtain the princinple eigenvector of matrix set (G1,G2). Which function should I use? eigs or eig? Also I want to know their computational complexity, I guess is around O(n^3)? n is the matrix dimension.
Thanks
  1 Comment
Oguz Kaan Hancioglu
Oguz Kaan Hancioglu on 3 Apr 2023
Eigs returns subset of eig command. If you examine all eigenvector both commands are the same. You can call eigs command with the subset dimensions. I don't know anything about the time complexity. Also in eigs comment there is a comment from matlab:
  • "Using eigs is not the most efficient way to find a few eigenvalues of small, dense matrices. For such problems, it might be quicker to use eig(full(A)). For example, finding three eigenvalues in a 500-by-500 matrix is a relatively small problem that is easily handled with eig."
Also there no code generation for eigs.
After you get the eigenvector, you can use vector opearions (such as max) to find princinpal eigenvectors.
Best.

Sign in to comment.

Answers (1)

Vandit
Vandit on 4 Apr 2023
The choice of whether to use “eig” or “eigs” function depends on the size of the matrix and the desired accuracy.
"eig" function is used to calculate all the eigenvalues and eigenvectors of a matrix so its computational complexity is O(n^3) for a matrix of size n x n. Therefore, if the size of the matrix is relatively small and you need all the eigenvalues and eigenvectors, you can use the "eig" function to obtain the principal eigenvector of the matrix set.
On the other hand, if the size of the matrix is large and you only need the principal eigenvector or a few eigenvalues and eigenvectors of a matrix then "eigs" function can be more efficient.
The computational cost of the "eigs" function is much lower than that of the "eig" function for large matrices, as it only computes a few eigenvalues and eigenvectors instead of all of them.
You can refer to the syntax of the both the functions using the link given below:

Categories

Find more on Eigenvalues & Eigenvectors in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!