 function [V, T] = lancz(v, A, m) 
%% function [T, V] = lancz(v, A, m) 
%% performs k steps of Lanczos. 
%% result will be a matrix T_m of size (m+1) x m
%% and orthogonal basis V[:,1:m+1] 
%% the relation A V_m = T_m V_{m+1} is satisfied.
%%
   t = norm(v,2);
   v = v/t; 
   beta = 0; 
   V(:,1)= v; 
   vold = v;
   for k=1:m
       w = A * v - beta*vold ; 
       alpha = w'*v; 
       T(k,k) = alpha; 
       w = w - alpha*v;
%%-------------------- reorthogonalization
       w = w - V* (V'*w);
       beta = norm(w,2) ; 
       vold = v; 
       v = w/ beta;
       V(:,k+1) = v;
       T(k,k+1) = beta; 
       T(k+1,k) = beta; 
   end
       
 
