newton <- function ( f, fp, x, tol = 1.0e-3, m = 100 ) #*****************************************************************************80 # ## newton seeks the root of a function using Newton's method. # # Licensing: # # Copyright 2016 James P. Howard, II # # The computer code and data files on this web page are distributed under # https://opensource.org/licenses/BSD-2-Clause, the BSD-2-Clause license. # # Modified: # # 13 March 2020 # # Author: # # Original R code by James Howard; # Modifications by John Burkardt. # # Reference: # # James Howard, # Computational Methods for Numerical Analysis with R, # CRC Press, 2017, # ISBN13: 978-1-4987-2363-3. # { iter <- 0 oldx <- x + 10.0 * tol while ( tol < abs ( x - oldx ) ) { iter <- iter + 1 if ( m < iter ) { warning ( 'newton: iteration limit exceeded.' ) break } oldx <- x x <- x - f ( x ) / fp ( x ) } return ( x ) }