## Rosenbrock function
rosenbrock <- function(x) {
n <- length(x)
x1 <- x[2:n]
x2 <- x[1:(n-1)]
sum(100*(x1-x2^2)^2 + (1-x2)^2)
}
nelder_mead(c(0, 0), rosenbrock)
# $xmin
# [1] 0.9999969 0.9999936
# $fmin
# [1] 1.131857e-11
# $nfeval
# [1] 47
nelmin(c(0, 0), rosenbrock)
# $xmin
# [1] 1 1
# $fmin
# [1] 1.389895e-17
# $nfeval
# [1] 200
# $restarts
# [1] 0
nelminb(c(0, 0), rosenbrock, c(-0.5,-0.5), c(0.5,0.5))
# $xmin
# [1] 0.50 0.25
# $fmin
# [1] 0.25
# $nfeval
# [1] 195
# $restarts
# [1] 0
Run the code above in your browser using DataLab