X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=optimization%2Fpreconditioned_conjugate_gradient_method.m;h=f3ff7e2fd56b36e99d6c478cb1a75a18f2bbe170;hp=cd886084a9766e1d785df59185c358ae69d75cc7;hb=7240c54725b82c037dfb6e43bedefbb1bf47a0bc;hpb=4c5f15b69f6795a22c662a9e22ddd649c65872cb diff --git a/optimization/preconditioned_conjugate_gradient_method.m b/optimization/preconditioned_conjugate_gradient_method.m index cd88608..f3ff7e2 100644 --- a/optimization/preconditioned_conjugate_gradient_method.m +++ b/optimization/preconditioned_conjugate_gradient_method.m @@ -14,8 +14,7 @@ function [x, k] = preconditioned_conjugate_gradient_method(Q, ... % min [phi(x) = (1/2)* + ] % % using the preconditioned conjugate gradient method (14.56 in - % Guler). If ``M`` is the identity matrix, we use the slightly - % faster implementation in conjugate_gradient_method.m. + % Guler). % % INPUT: % @@ -66,7 +65,8 @@ function [x, k] = preconditioned_conjugate_gradient_method(Q, ... % % We use this in the inner loop. - sqrt_n = floor(sqrt(length(x0))); + n = length(x0); + sqrt_n = floor(sqrt(n)); % Set k=0 first, that way the references to xk,rk,zk,dk which % immediately follow correspond (semantically) to x0,r0,z0,d0. @@ -90,8 +90,8 @@ function [x, k] = preconditioned_conjugate_gradient_method(Q, ... % So if it's too close to zero, we replace it with something % comparable but non-zero. - if (abs(dkQdk) < eps) - dkQdk = sign(dkQdk)*eps; + if (dkQdk < eps) + dkQdk = eps; end alpha_k = rkzk/dkQdk;