/* nag_zero_cont_func_brent_rcomm (c05azc) Example Program. * * Copyright 2006 Numerical Algorithms Group. * * Mark 9, 2009. */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpout; /* Scalars */ Integer exit_status = 0; double fx, tolx, x, y; Integer ind; Nag_ErrorControl ir; /* Arrays */ double c[17]; 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_brent_rcomm (c05azc) Example Program Results\n"); fprintf(fpout, "\n Iterations\n"); tolx = 1e-05; x = 0.0; y = 1.0; ir = Nag_Mixed; ind = 1; /* nag_zero_cont_func_brent_rcomm (c05azc). * Locates a simple zero of a continuous function. * Reverse communication. */ while (ind != 0) { nag_zero_cont_func_brent_rcomm(&x, &y, fx, tolx, ir, c, &ind, &fail); if (ind != 0) { fx = exp(-x) - x; fprintf(fpout, " x = %8.5f fx = %13.4e ind = %2ld\n", x, fx, ind); } } if (fail.code == NE_NOERROR) { fprintf(fpout, "\n Solution\n"); fprintf(fpout, " x = %8.5f y = %8.5f\n", x, y); } else { fprintf(fpout, "%s\n", fail.message); if (fail.code == NE_PROBABLE_POLE || fail.code == NW_TOO_MUCH_ACC_REQUESTED) { fprintf(fpout, " x = %8.5f y = %8.5f\n", x, y); } exit_status = 1; goto END; } END: if (fpout != stdout) fclose(fpout); return exit_status; }