f <- function(x, a=2, b=4) (x[1]-a)^2+(x[2]-b)^2
g <- function(x, a=2, b=4) c(2*(x[1]-a), 2*(x[2]-b))
## Using optim
algo1 <- algoObj("optim")
minFit(algo1, start=c(1,1), fct=f, gr=g, method="BFGS", b=6)
## Using nlm: very different structure, but same call
algo2 <- algoObj("nlm")
minFit(algo2, start=c(1,1), fct=f, gr=g, b=6)
Run the code above in your browser using DataLab