Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

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 guided 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
share|improve this question
    
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? –  Stefano M Jan 21 '13 at 12:41
    
It seems to be a small dense matrix when looking in the first lines of his code. –  vanCompute Jan 21 '13 at 12:51

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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