function [alpha, beta] = hw5lanczos(A,q1,btol,kmax);
%
% Run a basic Lanczos iteration until either beta_k < btol
% or k == kmax.

k = 0;
qk = 0;
r = q1;
b = 1;
while (b > btol) & (k < kmax)
k = k+1;
qkm1 = qk;
qk = r/b;
Aqk = A*qk;
alpha(k) = qk'*Aqk;
r = Aqk-qk*alpha(k)-qkm1*b;
b = norm(r);
beta(k) = b;
end