function IteracniPolynomy()

Lambda = [1:9,15]
n = length(Lambda);
A = diag(Lambda);
b = ones(n,1); u = zeros(n,1);

% Richardsonova metoda
omega = 2/(Lambda(1)+Lambda(end));
lambda = 0:0.01:Lambda(end);
rho = 1-omega*lambda;

% metoda sdruz. gradientu
r = b - A*u;
  elambda = ones(1,length(lambda));
  eLambda = ones(1,length(Lambda));
p = r;
  plambda = lambda;
  pLambda = Lambda;

figure
for k=1:n
    hold off
    plot(lambda,rho.^k,'b',...
        lambda,abs(rho(end).^k)*ones(1,length(lambda)),'b--',...
        lambda,-abs(rho(end).^k)*ones(1,length(lambda)),'b--')
    
    % Cebysevova metoda
    i = 0:k-1;
    xvlnka = cos((2*i+1)*pi./(2*k));
    lambdak = 0.5*(Lambda(1)+Lambda(end)-(Lambda(end)-Lambda(1))*xvlnka);
    rhoCeb = 1;
    rhoCebLambda = 1;
    for i=0:k-1
        rhoCeb = rhoCeb .* (lambda-lambdak(i+1))./(-lambdak(i+1));
        rhoCebLambda = rhoCebLambda .* (Lambda-lambdak(i+1))./(-lambdak(i+1));
    end
    hold on
    plot(lambda,rhoCeb,'r')
    
    hold on
    plot(lambda,abs(min(rhoCeb))*ones(1,length(lambda)),'r--',...
        lambda,-abs(min(rhoCeb))*ones(1,length(lambda)),'r--')
    
    % metoda sdruzenych gradientu
    alfa = (r'*p)/(p'*A*p);
    u = u + alfa*p;
      elambda = elambda - alfa*plambda;
      eLambda = eLambda - alfa*pLambda;
    r = b - A*u;
    beta = -(r'*A*p)/(p'*A*p);
    p = r + beta*p;
      plambda = lambda.*elambda+beta*plambda;
      pLambda = Lambda.*eLambda+beta*pLambda;
    hold on
    plot(lambda,elambda,'g',Lambda,eLambda,'go')
    
    log = sprintf('Cebysev vers. sdruzene gradienty - %d. iterace (z %d)',k,n);
    disp(log);
    log = sprintf('    konvergence v euklidovske norme: %g vers. %g',norm(rhoCebLambda)/norm(b),norm(eLambda)/norm(b));
    disp(log)
    log = sprintf('    konvergence v energeticke norme: %g vers. %g',norm(sqrt(Lambda).*rhoCebLambda)/norm(Lambda),norm(sqrt(Lambda).*eLambda)/norm(Lambda));
    disp(log)
    
    pause
end