/*********************************************** Test Routine (Rosenblock function) f(x0,x1) = 100*(x1-x0^2)^2 + (1-x0)^2 (xinit, yinit) = (-1.2, 1.0) (xopt, yopt) = (1, 1) fopt = 0 ************************************************/ #include #include #include #include "opt.h" static double Rosenblock(int n, double x[]) { double x0, x1; x0 = x[0]; x1 = x[1]; return 100*(x1-x0*x0)*(x1-x0*x0) + (1-x0)*(1-x0); } main() { int n = 2; double x[2]; double length = 1.00; double fopt; int timeout = 1000; double eps = 1e-30; x[0] = -1.2; x[1] = 1.0; if (NelderMeadSimplexMethod(n, Rosenblock, x, length, &fopt, timeout, eps) == success) { printf("reaching to minimum "); } else { printf("timeout "); } printf(" [ %lf %lf ] %lf\n", x[0], x[1], fopt); }