Simplify the loop in vanilla_cgm().
sqrt_n = floor(sqrt(length(x0)));
k = 0;
sqrt_n = floor(sqrt(length(x0)));
k = 0;
- xk = x0; % Eschew the 'k' suffix on 'x' for simplicity.
rk = A*xk - b; % The first residual must be computed the hard way.
pk = -rk;
rk = A*xk - b; % The first residual must be computed the hard way.
pk = -rk;
- while (k <= max_iterations)
- if (norm(rk) < tolerance)
- % Success.
- x = xk;
- return;
- end
-
+ while (k <= max_iterations && norm(rk, 'inf') > tolerance)
alpha_k = step_length_cgm(rk, A, pk);
x_next = xk + alpha_k*pk;
alpha_k = step_length_cgm(rk, A, pk);
x_next = xk + alpha_k*pk;