# Simple Lanczos algorithm code to obtain eigenvalues and eigenvectors of a symmetric matrix

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

-
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