grpracma | R Documentation |
Provides a wrapper for the numDeriv approximation to the
gradient of a user supplied objective function userfn
.
grpracma(par, userfn, ...)
par |
A vector of parameters to the user-supplied function |
userfn |
A user-supplied function |
... |
Other data needed to evaluate the user function. |
The Richardson method is used in this routine.
grpracma
returns an approximation to the gradient of the function userfn
cat("Example of use of grpracma\n")
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)
gn<-grpracma(xx,myfn, shift=0)
print(gn)
ga<-ii*xx^(ii-1)
cat("compare to\n")
print(ga)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.