grcentral: Central difference numerical gradient approximation.

Description Usage Arguments Details Value Author(s) Examples

View source: R/grcentral.R

Description

grcentral computes the central difference approximation to the gradient of user function userfn.

Usage

1
   grcentral(par, userfn, eps=1.0e-7, ...)

Arguments

par

parameters to the user objective function userfn

userfn

User-supplied objective function

eps

a small number used to generate the finite difference step

...

optional arguments passed to the objective function.

Details

Package: grcentral
Depends: R (>= 2.6.1)
License: GPL Version 2.

Value

grcentral returns a single vector object df which approximates the gradient of userfn at the parameters par.

Author(s)

John C. Nash

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
cat("Example of use of grfwd\n")

myfn<-function(xx, shift=100){
    ii<-1:length(xx)
    result<-shift+sum(xx^ii)
}
xx<-c(1,2,3,4)
ii<-1:length(xx)
print(xx)
gn<-grcentral(xx,myfn, shift=0)
print(gn)
ga<-ii*xx^(ii-1)
cat("compare to\n")
print(ga)

optfntools documentation built on May 2, 2019, 4:26 p.m.