gd <- function ( fp, x, h = 1.0e-2, tol = 1.0e-4, m = 1000 ) #*****************************************************************************80 # ## gd seeks the minimum of a multivariate function using gradient descent. # # 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: # # 15 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. # { source ( "/home/burkardt/public_html/r_src/vecnorm/vecnorm.R" ) iter <- 0 oldx <- x x <- x - h * fp ( x ) while ( tol < vecnorm ( x - oldx ) ) { iter <- iter + 1 if ( m < iter ) { warning ( 'gd: iteration limit exceeded.' ) return ( x ) } oldx <- x x <- x - h * fp ( x ) } return ( x ) }