main.m1167 chars41 lines
This code defines a function mynewton
which takes as input a function handle f
, a Jacobian matrix function handle J
, an initial guess x0
, a tolerance tol
, and a maximum number of iterations maxIt
. The function returns the zero found in x
and a convergence flag conv
indicating whether the method converged or not.
Inside the function, the multidimensional Newton's method is implemented using a loop that computes the function value fx
and the Jacobian matrix Jx
at the current point x0
, solves the linear system Jx s = -fx
for the search direction s
, and updates the current point as x0 = x0 + s
. The loop continues until either the norm of the function value is smaller than the tolerance tol
or the maximum number of iterations maxIt
is reached.
Note that the backslash operator \
is used to solve the linear system in a computationally efficient manner. The function also assumes that the method will diverge if the maximum number of iterations is reached without convergence.
gistlibby LogSnag