function lanczos(A,ns)
  
  [n,nn]=size(A);
  
  qhold = randn(n,1);  % Erzeugt zufaelligen Anfangsvektor
  qhold = qhold/norm(qhold);
  
  hold on
  
  q(:,1)=qhold;
  
  mem=A*q(:,1);
  T(1,1)=q(:,1)'*mem;
  r=mem-T(1,1)*q(:,1);
  T(1,2)=norm(r);
  q(:,2)=r./T(1,2);
  T(2,1)=T(1,2)';
  
  for k=2:ns-1;
    mem=A*q(:,k);
    T(k,k)=q(:,k)'*mem;
    r=mem-T(k-1,k)*q(:,k-1)-T(k,k)*q(:,k);
    T(k,k+1)=norm(r);
    q(:,k+1)=r./T(k,k+1);
    T(k+1,k)=T(k,k+1)';
    plot(k*ones(k,1),eig(T(1:k,1:k)),'.')
    pause(.25)
  end
  T(ns,ns)=q(:,ns)'*A*q(:,ns);
  hold off
  


