zk = M \ rk;
dk = -zk;
- for k = [ 0 : max_iterations ]
+ while (k <= max_iterations)
if (norm(rk) < tolerance)
% Check our stopping condition. This should catch the k=0 case.
beta_next = (r_next' * z_next)/rkzk;
d_next = -z_next + beta_next*dk;
+ % We potentially just performed one more iteration than necessary
+ % in order to simplify the loop. Note that due to the structure of
+ % our loop, we will have k > max_iterations when we fail to
+ % converge.
k = k + 1;
xk = x_next;
rk = r_next;