function prikladRichardson2()

[uzly,prvky,ID] = diskretizuj_obdelnik(1,1,0.1);
n = size(uzly,2);
m = size(prvky,2);
f = zeros(1,m);
for i=1:m
    ti = sum(uzly(:,prvky(:,i)),2)/3;
    f(i) = sin(8*pi*ti(1))*cos(8*pi*ti(2))+sin(4*pi*ti(1))*cos(4*pi*ti(2)) + sin(pi*ti(1))*cos(pi*ti(2));
end
[A,b] = mkp_2d(uzly,prvky,f,ID);
u = A\b;
trisurf(prvky',uzly(1,:),uzly(2,:),u)
title('reseni')
pause

[V,D] = eig(full(A));
[lambdamax,imax] = max(diag(D));
'nejrychleji oscilujici vlastni vektor odpovida lambdamax'
trisurf(prvky',uzly(1,:),uzly(2,:),V(:,imax))
title('emax')
pause
[lambdamin,imin] = min(diag(D));
'nejpomaleji oscilujici vlastni vektor odpovida lambdamin'
trisurf(prvky',uzly(1,:),uzly(2,:),V(:,imin))
title('emin')
pause



'rychle oscilujici slozky rezidua konverguje rychle, pomalu uscilujici konverguji pomalu'
omega = 1/Gershgorin(A);
u = zeros(n,1);
for i=1:100
    [u,k] = Richardson(A,b,u,omega,1e-3,1);
    r = b - A*u;
    trisurf(prvky',uzly(1,:),uzly(2,:),r)
    if i==1
        v = axis;
    end
    axis(v)
    str = sprintf('|r^{%d}| / |r^0| = %g',i,norm(r)/norm(b));
    title(str)
    pause
end
