Re: How to vectorize functions like eig()



On Thu, 07 Feb 2008 12:10:03 -0500, Stephane Carlier <youfellow@xxxxxxxxxxx> wrote:
This is exactly the "for loop" I wish to avoid. I am not
talking about only 4 matrices. Actually the problem I have
involves about 2e6 matrices. I had a similar problem with
2x2 matrices, but luckily I can derive an analytical
solution for eigenvalues for 2x2 matrices. The speed
improvement of my analytical solution vs eig() loop is about
60x faster. For 3x3 matrices, the analytical solution is
still possible. But before I invest all the time in coding
those fairly complicated equations, I wish to know if the
numerical method can be faster than the analytical method.

i could very well be wrong, but i think eig() only takes 2-
d matrices. i'd like to think, though, that the optimizer
should make a for-loop fairly quick if you just indexed the
big array and called eig on its sections:

% 4 3x3 matrices
>>mat=rand([12 3]);
>>for i = 1:3:length(mat)
eig(mat(i:i+2,:))
end

something in that form shouldn't be too taxing although
it's not "vectorized"...


If you have access to Maple, you might be able to automatically generate the analytical solution and the corresponding Matlab code, using its CodeGeneration package. However, the analytical roots to the 3rd order polynomials are so complex that I'm guessing you won't gain that much benefit over an iterative approximation.

If you're only concern is calculating eigenvalues as fast as possible, you probably need to switch to a lower level language (C or Fortran), and use libraries that are optimized for your processor (e.g. the Intel Math Kernel Library for Intel processors).

--Arthur
.



Relevant Pages

  • Re: How to vectorize functions like eig()
    ... This is exactly the "for loop" I wish to avoid. ... improvement of my analytical solution vs eig() loop is about ... For 3x3 matrices, the analytical solution is ... numerical method can be faster than the analytical method. ...
    (comp.soft-sys.matlab)
  • Re: Help for a basic problem
    ... If no analytical solution is available, how can I get it, by numerical method? ... by using solveand rectform() in Macsyma. ...
    (sci.math.symbolic)

Loading