function [u,k] = twogrid_iter(A,b,prec)

n = length(b);
u = zeros(n,1);
r = b-A*u;
norm0 = norm(r);

k = 0;

while norm(r)/norm0 > prec
    u = u + twogrid(r);
    r = b-A*u;
    k = k+1;
end
