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

u = u0;
r0 = b-A*u;
z0 = B*r0;
Atildanormr0 = sqrt(r0'*z0);
Atildanormr = Atildanormr0;
r = r0;
z = z0;
p = z;
it = 0;

while Atildanormr>prec*Atildanormr0 && it<itMax
    alfa = r'*z/(p'*A*p);
    u = u + alfa*p;
    rpred = r;
    r = r-alfa*A*p;
    zpred = z;
    z = B*r;
    Atildanormr = sqrt(r'*z);
    beta = (r'*z)/(rpred'*zpred);
    p = z + beta*p;
    it = it+1;
end

