From 1894f0ed32e27eda86ad85065131151c17817895 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 25 Mar 2013 12:49:58 -0400 Subject: [PATCH] Use the infinity norm in vanilla_cgm(). Simplify the loop in vanilla_cgm(). --- optimization/vanilla_cgm.m | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/optimization/vanilla_cgm.m b/optimization/vanilla_cgm.m index 9ada2cb..c4d8f07 100644 --- a/optimization/vanilla_cgm.m +++ b/optimization/vanilla_cgm.m @@ -40,17 +40,11 @@ function [x, k] = vanilla_cgm(A, b, x0, tolerance, max_iterations) sqrt_n = floor(sqrt(length(x0))); k = 0; - xk = x0; % Eschew the 'k' suffix on 'x' for simplicity. + xk = x0; 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; -- 2.43.2