function [u,k] = conjugate_directions(A,b,u0,prec,V)

n = length(b);
u = u0;
r = b - A*u;
k = 0;
normk = norm(r);
initNorm = normk;

while normk/initNorm > prec
    v = V(:,k+1);
    alpha = (v'*r)/(v'*A*v);
    u = u + alpha*v;
    r = b - A*u;
    normk = norm(r);
    k = k+1;
end