Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(Rcpp)
- sourceCpp("optim_cpp.cpp")
- 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))
- }
- optim_cpp(fr, grr, c(-1.2,1), method = "BFGS")
- optim(c(-1.2,1), fr, grr, method = "BFGS")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement