X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=optimization%2Fconjugate_gradient_method.m;h=9b2ddac24377e5d02651f7b9e52a5ee3a4c0707c;hp=5b07e1c183f88f5f0764975a23edc1c27dad446e;hb=6e504c235e5e2ad1abc0a98b733ed2269936c17a;hpb=da77431bfbbb5fed8835d09aeea0de7eb7f6194a diff --git a/optimization/conjugate_gradient_method.m b/optimization/conjugate_gradient_method.m index 5b07e1c..9b2ddac 100644 --- a/optimization/conjugate_gradient_method.m +++ b/optimization/conjugate_gradient_method.m @@ -1,40 +1,40 @@ function x_star = conjugate_gradient_method(A, b, x0, tolerance) - ## - ## Solve, - ## - ## Ax = b - ## - ## or equivalently, - ## - ## min [phi(x) = (1/2)* + ] - ## - ## using Algorithm 5.2 in Nocedal and Wright. - ## - ## INPUT: - ## - ## - ``A`` -- The coefficient matrix of the system to solve. Must - ## be positive definite. - ## - ## - ``b`` -- The right-hand-side of the system to solve. - ## - ## - ``x0`` -- The starting point for the search. - ## - ## - ``tolerance`` -- How close ``Ax`` has to be to ``b`` (in - ## magnitude) before we stop. - ## - ## OUTPUT: - ## - ## - ``x_star`` - The solution to Ax=b. - ## - ## NOTES: - ## - ## All vectors are assumed to be *column* vectors. - ## + % + % Solve, + % + % Ax = b + % + % or equivalently, + % + % min [phi(x) = (1/2)* + ] + % + % using Algorithm 5.2 in Nocedal and Wright. + % + % INPUT: + % + % - ``A`` -- The coefficient matrix of the system to solve. Must + % be positive definite. + % + % - ``b`` -- The right-hand-side of the system to solve. + % + % - ``x0`` -- The starting point for the search. + % + % - ``tolerance`` -- How close ``Ax`` has to be to ``b`` (in + % magnitude) before we stop. + % + % OUTPUT: + % + % - ``x_star`` - The solution to Ax=b. + % + % NOTES: + % + % All vectors are assumed to be *column* vectors. + % zero_vector = zeros(length(x0), 1); k = 0; xk = x0; - rk = A*xk - b; # The first residual must be computed the hard way. + rk = A*xk - b; % The first residual must be computed the hard way. pk = -rk; while (norm(rk) > tolerance)