Does ordinary "eig" calculate eigenvalues faster than "polyeig"?
20 views (last 30 days)
Show older comments
I want to compare the computational complexity (computational order) of obtaining eigenvalues (not eigenvectors) of two methods:
- Ordinary eigenvalue calculation, such as "eig" function.
- Polynomial approach, which corresponds to the "polyeig" function.
The main point is that MATLAB consumes less time with "eig" function than "polyeig", however the matrices in the "polyeig" method are smaller in size. Also, there is a line in explanation of "polyeig" which says: " The polyeig function uses the qz factorization to find intermediate results in the computation of generalized eigenvalues. polyeig uses the intermediate results to determine if the eigenvalues are well-determined". Furthermore "eig" uses LU-decomposition in its function, where "polyeig" uses qz decomposition.
My questions are:
1) I think MATLAB's "tic-toc" function is not a proper tool for comparison between these two functions, due to the fact that they uses different methods and "polyeig" checks its answers. Is this suggestion right?
2) For a fair comparison, should I write my own program which calculates eigenvalues in both methods (polynomial and ordinary)?
4 Comments
Christine Tobler
on 9 Aug 2018
That's correct, all solvers for polynomial eigenvalue problems I am aware of are in some way generalizations of solvers for the simple or generalized eigenvalue problems. They will typically be slower when applied to the same problem.
The solver used in MATLAB calls into EIG directly, with matrices of size n*p, where n is the size of the input matrices, and p is the polynomial degree of the eigenvalue problem.
Since the computational complexity of EIG is O(n^3), the computational complexity of POLYEIG is O(p^3*n^3).
Answers (1)
Pavl M.
on 24 Oct 2024
clc
clear all
close all
%format native-bit
format longg
rand('state',1)
%for ProblemComplexty = 2:1:1000
ProblemComplexity = 4;
%[a1,b1] = eig(ones(4,4))
%[a,b,c] = polyeig([ones(1,4);zeros(1,4);zeros(1,4);zeros(1,4)],[zeros(1,4);ones(1,4);zeros(1,4);zeros(1,4)],[zeros(1,4);zeros(1,4);ones(1,4);zeros(1,4)],[zeros(1,4);zeros(1,4);ones(1,4);zeros(1,4)])
A = randn(ProblemComplexity,ProblemComplexity)
B = randn(ProblemComplexity,ProblemComplexity)
tstart = cputime;
[V,D,W] = eig(A,B)
first_method_took_time_sec = cputime - tstart
tstart2 = cputime;
[X,e,s] = polyeig(A,-B)
second_method_took_time_sec = cputime - tstart2
speedup = 100*(first_method_took_time_sec - second_method_took_time_sec) / (first_method_took_time_sec)
%end for
%Constructed from needing help code by
%https://independent.academia.edu/PMazniker
%+380990535261
%https://diag.net/u/u6r3ondjie0w0l8138bafm095b
%https://github.com/goodengineer
%https://orcid.org/0000-0001-8184-8166
%https://willwork781147312.wordpress.com/portfolio/cp/
%https://www.youtube.com/channel/UCC__7jMOAHak0MVkUFtmO-w
%https://nanohub.org/members/130066
%https://pangian.com/user/hiretoserve/
%https://substack.com/profile/191772642-paul-m
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!