# \donttest{
## Minimize Rosenbrock function
fn <- function(x) {
# Objective
f <- 100*(x[2] - x[1]^2)^2 + (1-x[1])^2
# Gradient
g <- c(-400*x[1]*(x[2] - x[1]^2) - 2*(1-x[1]),
200*(x[2] - x[1]^2))
list(f, g)
}
(res <- efficient_bfgs(c(0.5, 2.5), fn))
## Compare to
(res0 <- stats::optim(c(0.5, 2.5), function(x)fn(x)[[1]], hessian = TRUE))
solve(res0$hessian)
# }
Run the code above in your browser using DataLab