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