Given a symmetric positive semidefinite matrix $A$, find an eigenpair $(\lambda,v)$ such that $A v = \lambda v$ with $\lambda$ maximal in the shortest amount of time.
My approaches:
- power iteration
pseudocode:
x:=random vector of length numrows(A) x=x/||x||
while l changes (e.g. abs(l-l_last)<tolerance)
x=Av
l=||x||
x=x/||x||
very slow but it works. I generated 100 times a 100x100 random A (sym.,pos.def.) and i get an average runtime of 0.015s in matlab. (i also implemented this in c++ with little improvements)
- inverse iteration:
pseudocode:
x:=random vector of length numrows(A)
x=x/||x||
l=2*max(A(i,j)) % start with a value above the maximal lambda
while l changes
x=(A-l*I)^-1 * v
x=x/||x||
l=x'*A*x %rayleigh quotient
i get an average runtime of 0.0136s. (i compute (A-l*I)^-1 with lu decomposition)
Now the mindtwisting part:
Matlab has a build in function called "eig" that computes all(!) eigenvalues about 10 times faster (average ~3e-4s with the above A)... To top it all off: I did compare the eigenvalues of 100 reruns (for the same A) and the matlab solution does change exactly 0. So they use a symbolic computation???... I know matlab is very secret about everything they do, but is there maybe a pseudo code or even a hint how i can do better? Seems like the power iteration/inverse power iteration/rayleigh... is very out-of-date?
(btw: matlab does not use svd=single value decomposition, since svd takes much longer than eig.)
For anyone that has the same problem, here is a solution/template using lapack (thanks MrYouMath) in c++: