/* nag_zero_cont_func_bd (c05adc) Example Program. * * Copyright 1991 Numerical Algorithms Group. * * Mark 2, 1991. * Mark 7 revised, 2001. */ #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif static double f(double x); #ifdef __cplusplus } #endif int main(void) { double a, b; double x, ftol, xtol; static NagError fail; Vprintf("nag_zero_cont_func_bd (c05adc) Example Program Results\n"); a = 0.0; b = 1.0; xtol = 1e-05; ftol = 0.0; /* nag_zero_cont_func_bd (c05adc). * Zero of a continuous function of one variable */ nag_zero_cont_func_bd(a, b, &x, f, xtol, ftol, &fail); if (fail.code == NE_NOERROR) { Vprintf("Zero = %12.5f\n",x); return EXIT_SUCCESS; } else { Vprintf("%s\n", fail.message); if (fail.code == NE_XTOL_TOO_SMALL || fail.code == NE_PROBABLE_POLE) Vprintf("Final point = %12.5f\n",x); return EXIT_FAILURE; } } static double f(double x) { return exp(-x)-x; }