# NOT RUN {
## These are taken from the numDeriv::grad examples to show how
## simple gradients are assessed with nlmixrGill83
nlmixrGill83(sin, pi)
nlmixrGill83(sin, (0:10)*2*pi/10)
func0 <- function(x){ sum(sin(x)) }
nlmixrGill83(func0 , (0:10)*2*pi/10)
func1 <- function(x){ sin(10*x) - exp(-x) }
curve(func1,from=0,to=5)
x <- 2.04
numd1 <- nlmixrGill83(func1, x)
exact <- 10*cos(10*x) + exp(-x)
c(numd1$df, exact, (numd1$df - exact)/exact)
x <- c(1:10)
numd1 <- nlmixrGill83(func1, x)
exact <- 10*cos(10*x) + exp(-x)
cbind(numd1=numd1$df, exact, err=(numd1$df - exact)/exact)
sc2.f <- function(x){
n <- length(x)
sum((1:n) * (exp(x) - x)) / n
}
sc2.g <- function(x){
n <- length(x)
(1:n) * (exp(x) - 1) / n
}
x0 <- rnorm(100)
exact <- sc2.g(x0)
g <- nlmixrGill83(sc2.f, x0)
max(abs(exact - g$df)/(1 + abs(exact)))
# }
Run the code above in your browser using DataLab