- zero_vector = zeros(length(x0), 1);
-
- k = 0;
- xk = x0;
- rk = A*xk - b; % The first residual must be computed the hard way.
- pk = -rk;
-
- while (norm(rk) > tolerance)
- alpha_k = step_length_cgm(rk, A, pk);
- x_next = xk + alpha_k*pk;
- r_next = rk + alpha_k*A*pk;
- beta_next = (r_next' * r_next)/(rk' * rk);
- p_next = -r_next + beta_next*pk;
-
- k = k + 1;
- xk = x_next;
- rk = r_next;
- pk = p_next;
- end
+ % The rather verbose name of this function was chosen to avoid
+ % conflicts with other implementations.
+ %
+ n = length(x0);
+ M = eye(n);