/* test_optmn.c initial tests */ #include #include "optmn.h" static double f2(double x[]) { return (x[0]-0.4)*(x[0]-0.4) + (x[1]+0.6)*(x[1]+0.6); } static double f3(double x[]) { return (x[0]-0.4)*(x[0]-0.4) + (x[1]+0.6)*(x[1]+0.6) + (x[2]-0.3)*(x[2]-0.3); } static double f4(double x[]) { return (x[0]-0.4)*(x[0]-0.4) + (x[1]+0.6)*(x[1]+0.6) + (x[2]-0.3)*(x[2]-0.3) + (x[3]-0.7)*(x[3]-0.7); } int main(int argc, char *argv[]) { int n2 = 2; int n3 = 3; int n4 = 4; double xmax[6] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; double xmin[6] = {-1.0, -1.0, -1.0, -1.0, -1.0, -1.0}; double x[6]; int maxcnt; double tol = 0.001; double yfinal = 0.001; double step[6]; double y; int i; printf("test_optmn.c running \n"); maxcnt = 20; srchn(n2, /* number of parameters */ x, /* returned best found */ &y, /* returned value of function */ maxcnt, /* maximum number of tries */ xmin, /* minimum value for each x */ xmax, /* maximum value for each x */ f2); /* function to be evaluated */ printf("f2 search value = %g at: \n", y); for(i=0; i