grpracma.RdProvides a wrapper for the pracma package approximation to the
gradient of a user supplied objective function userfn.
grpracma(par, userfn, ...)A central difference approximation is used in this routine.
grpracma returns an approximation to the gradient of the function userfn
cat("Example of use of grpracma\n")
#> Example of use of grpracma
require(numDeriv)
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)
#> [1] 1 2 3 4
gn<-grpracma(xx,myfn, shift=0)
print(gn)
#> [1] 1 4 27 256
ga<-ii*xx^(ii-1)
cat("compare to\n")
#> compare to
print(ga)
#> [1] 1 4 27 256