/* 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 #include #ifdef __cplusplus extern "C" { #endif static double NAG_CALL f(double x); #ifdef __cplusplus } #endif int main(int argc, char *argv[]) { FILE *fpout; Integer exit_status = 0; double a, b; double x, ftol, xtol; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "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) { fprintf(fpout, "Zero = %12.5f\n", x); } else { fprintf(fpout, "%s\n", fail.message); if (fail.code == NE_XTOL_TOO_SMALL || fail.code == NE_PROBABLE_POLE) fprintf(fpout, "Final point = %12.5f\n", x); exit_status = 1; goto END; } END: if (fpout != stdout) fclose(fpout); return exit_status; } static double NAG_CALL f(double x) { return exp(-x)-x; }