function [ret,steps]=aufg06f01(A,tol,var,lambda)

% A: n x n-Matrix
% tol: Toleranz fuer die Norm des Residuums
%         r = Av-lambda v
% var=0: Fester Shift lambda
% var=1: variabler Shift
% var=2: Rayleigh-Quotienten Shift
% lambda: Anfangsshift

if nargin < 4
   lambda = 0;
end
if nargin < 3
   var = 2;
end
if nargin < 2
   tol = 1e-10;
end
if nargin < 1
   A = rand(10);
   A = A+A'; %' nur so als Test ...
end

maxsteps = 100;

u = ones(size(A,1),1);
res = 1;
steps = 0;
I = speye(size(A)); %I = eye(n); % fuer octave

while (res>tol && steps<maxsteps),
    steps=steps+1;
    v=(lambda*I-A)\u;
    k=v(1);
    u=v/k;
    if var==0,
       res=norm(A*u-(lambda-1/k)*u)/norm(u);
    elseif var==1,
       lambda=lambda-1/k;
       res=norm(A*u-lambda*u)/norm(u);
    elseif var==2,
       w = A*u;
       uu = u'*u;
       lambda=u'*w/uu;
       res=norm(w-lambda*u)/sqrt(uu);
    end
    fprintf('Residuum in Schritt %2d : %g\n', steps, res);
end

if var==0
    ret=lambda-1/k;
else
    ret=lambda;
end;
