# NOT RUN {
#simple function to be optimized
fn = function(x){
x^2
}
#call downhillsimplex
res = downhillsimplex(fn,1,lower=-10,upper=10,it=1000,tol=1e-10)
#plot results
x = seq(-10,10,0.01)
plot(x,fn(x),type='l')
points(res[1],fn(res[1]),col='red')
legend('topleft',legend=c('Function', 'Estimated minimum'), col=c('black','red'),
lty=c(1,NA),pch=c(NA,1))
# }
Run the code above in your browser using DataLab