/* nag_opt_one_var_deriv(e04bbc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 7 revised, 2001. * */ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static void funct(double xc, double *fc, double *gc, Nag_Comm *comm); #ifdef __cplusplus } #endif static void funct(double xc, double *fc, double *gc, Nag_Comm *comm) { *fc = sin(xc) / xc; *gc = (cos(xc) - *fc) / xc; } /* funct */ int main(void) { double a, b; double e1, e2; double x, f, g; Integer max_fun; Nag_Comm comm; static NagError fail; Vprintf("e04bbc Example Program Results.\n\n"); /* e1 and e2 are set to zero so that e04abc will reset them to * their default values */ e1 = 0.0; e2 = 0.0; /* The minimum is known to lie in the range (3.5, 5.0) */ a = 3.5; b = 5.0; /* Allow 30 calls of funct */ max_fun = 30; fail.print = TRUE; e04bbc(funct, e1, e2, &a, &b, max_fun, &x, &f, &g, &comm, &fail); Vprintf("The minimum lies in the interval %7.5f to %7.5f.\n", a, b); Vprintf("Its estimated position is %7.5f,\n", x); Vprintf("where the function value is %9.4e\n",f); Vprintf("and the gradient is %9.4e.\n",g); Vprintf("%1ld function evaluations were required.\n", comm.nf); return EXIT_SUCCESS; }