X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=newtons_method.m;h=2d33c1a771b56329243603a94456a8bbbd147664;hp=8bdd090945b49b1e99f5c7d9790f73ac218909da;hb=b12c6c2a4bf4cef29b2e08b743c92889505c7ed9;hpb=e1b71b4ca7cfa08ac76744a17a3778d4ccfaa7e2 diff --git a/newtons_method.m b/newtons_method.m index 8bdd090..2d33c1a 100644 --- a/newtons_method.m +++ b/newtons_method.m @@ -1,25 +1,25 @@ function [root, iterations] = newtons_method(f, f_prime, epsilon, x0) - ## Find a root of the function `f` with initial guess x0. - ## - ## INPUTS: - ## - ## * ``f`` - The function whose root we seek. Must return a column - ## vector or scalar. - ## - ## * ``f_prime`` - The derivative or Jacobian of ``f``. - ## - ## * ``epsilon`` - We stop when the value of `f` becomes less - ## than epsilon. - ## - ## * ``x0`` - An initial guess. Either 1d or a column vector. - ## - ## OUTPUTS: - ## - ## * ``root`` - The root that we found. - ## - ## * ``iterations`` - The number of iterations that we performed - ## during the search. - ## + % Find a root of the function `f` with initial guess x0. + % + % INPUTS: + % + % * ``f`` - The function whose root we seek. Must return a column + % vector or scalar. + % + % * ``f_prime`` - The derivative or Jacobian of ``f``. + % + % * ``epsilon`` - We stop when the value of `f` becomes less + % than epsilon. + % + % * ``x0`` - An initial guess. Either 1d or a column vector. + % + % OUTPUTS: + % + % * ``root`` - The root that we found. + % + % * ``iterations`` - The number of iterations that we performed + % during the search. + % if (columns(x0) > 1) root = NA; @@ -31,8 +31,8 @@ function [root, iterations] = newtons_method(f, f_prime, epsilon, x0) f_val = f(x0); while (norm(f_val, Inf) > epsilon) - ## This uses the modified algorithm (2.11.5) in Atkinson. - ## Should work in 1d, too. + % This uses the modified algorithm (2.11.5) in Atkinson. + % Should work in 1d, too. delta = f_prime(xn) \ f_val; xn = xn - delta; f_val = f(xn);