function [u,it] = SdruzeneGradienty(A,b,u0,prec,itMax)

u = u0;
r0 = b-A*u;
Anormr0 = sqrt(r0'*A*r0);
Anormr = Anormr0;
r = r0;
p = r;
it = 0;

while Anormr>prec*Anormr0 && it<itMax
    alfa = r'*r/(p'*A*p);
    u = u + alfa*p;
    r = b-A*u;
    Anormr = sqrt(r'*A*r);
    beta = -r'*A*p/(p'*A*p);
    p = r + beta*p;
    it = it+1;
end

