6
$\begingroup$

I would like to write a simple program (in C) using Lanczos algorithm. I came across a Matlab example which helped me to understand a bit further the algorithm, however from this piece of code I can't find the way of getting the eigenvalues and eigenvectors. I can follow the algorithm but I think I must be missing something. Can someone guide me to get the eigenvalues from this example so I can understand the method and then code it in C?

% Create a random symmetric matrix 
D=6
for i=1:D,
    for j=1:i,
        A(i,j)=rand; 
        A(j,i)=A(i,j);
    end 
end

% Iteration with j=0 
r0 = rand(D,1); 
b0 = sqrt(r0'*r0); 
q1 = r0/b0; 
a1 = q1'*A*q1

%Iteration with j=1
r1 = A*q1 - a1*q1
b1 = sqrt(r1'*r1)
q2 = r1/b1;
a2 = q2'*A*q2

%Iteration with j=2
r2 = A*q2 - a2*q2 - b1*q1;
b2 = sqrt(r2'*r2)
q3 = r2/b2
a3 = q3'*A*q3

% Create Matrix Q
Q = [q1 q2 q3];

%Check orthogonality
EYE = Q'*Q
T = Q'*A*Q
$\endgroup$
2
  • $\begingroup$ I would not claim that Lanczos is a good choice for a "simple program". Please could you state which type of matrices (dense, sparse) and size (small, big) are you going to decompose? $\endgroup$
    – Stefano M
    Jan 21, 2013 at 12:41
  • $\begingroup$ It seems to be a small dense matrix when looking in the first lines of his code. $\endgroup$
    – vanCompute
    Jan 21, 2013 at 12:51

1 Answer 1

8
$\begingroup$

The Lanczos algorithm can be used to put the matrix into tridiagonal form, but it doesn't actually find the eigenvalues and eigenvectors of that tridiagonal matrix. Once you have the matrix in tridiagonal form, the QR algorithm is typically used to find the eigenvalues of the tridiagonal matrix.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.