#*****************************************************************************80 # ## gd_test tests gd. # # 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: # # John Burkardt # cat ( date ( ), "\n" ) cat ( "\n" ) cat ( "gd_test\n" ) cat ( " ", version$version.string, "\n" ) cat ( " gd seeks the minimum of a function using gradient descent.\n" ) cat ( "\n" ) source ( "/home/burkardt/public_html/r_src/gd/gd.R" ) fp <- function ( x ) { dfdx1 <- 2.0 * x[1] - 2.0 dfdx2 <- 8.0 * x[2] - 8.0 return ( c ( dfdx1, dfdx2 ) ) } x = c( 0.0, 0.0 ) h = 0.05 m = 5 value <- gd ( fp, x, h, m = m ) cat ( " gd((x-1)^2+(y-2)^2,[0,0],0.05,m=5) = ", value, "\n" ) x = c( 0.0, 0.0 ) h = 0.05 m = 20 value <- gd ( fp, x, h, m = m ) cat ( " gd((x-1)^2+(y-2)^2,[0,0],0.05,m=20) = ", value, "\n" ) # # Terminate. # cat ( "\n" ) cat ( "gd_test\n" ) cat ( " Normal end of execution.\n" ) cat ( date ( ), "\n" ) quit ( )