example1_rosen_bfgs: Example 1: Minimize Rosenbrock function using BFGS

View source: R/RcppExports.R

example1_rosen_bfgsR Documentation

Example 1: Minimize Rosenbrock function using BFGS

Description

Minimize Rosenbrock function using BFGS.

Usage

example1_rosen_bfgs(print = TRUE)

Arguments

print

whether the results should be printed.

Examples

fr <- function(x) {   ## Rosenbrock Banana function
 x1 <- x[1]
 x2 <- x[2]
 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
grr <- function(x) { ## Gradient of 'fr'
 x1 <- x[1]
 x2 <- x[2]
 c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1),
   200 *      (x2 - x1 * x1))
}
res <- optim(c(-1.2,1), fr, grr, method = "BFGS", control = list(trace=TRUE), hessian = TRUE)
res

## corresponding C++ implementation:
example1_rosen_bfgs()

roptim documentation built on Aug. 6, 2022, 5:08 p.m.