/* nag_interval_zero_cont_func (c05avc) 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 boundl, boundu, fx, h, x, y; Integer ind; /* Arrays */ double c[11]; NagError fail; INIT_FAIL(fail); /* Check for command-line IO options */ fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_interval_zero_cont_func (c05avc) Example Program Results\n"); x = 3.0; h = 0.1; boundl = 0.0; boundu = 4.0; ind = 1; /* nag_interval_zero_cont_func (c05avc). * Locates an interval containing a simple zero of a continuous * function using binary search and reverse communication. */ while (ind != 0) { nag_interval_zero_cont_func(&x, fx, &h, boundl, boundu, &y, c, &ind, &fail); if (ind != 0) { fx = pow(x, 2) - 3.0*x + 2.0; } } if (fail.code == NE_NOERROR) { fprintf(fpout, "Interval containing root is [x,y], where\n"); fprintf(fpout, "x = %12.4f, y = %12.4f\n", x, y); fprintf(fpout, "Values of f at x and y are\n"); fprintf(fpout, "f(x) = %12.2f, f(y) = %12.2f\n", fx, c[0]); } else { fprintf(fpout, "%s\n", fail.message); exit_status = 1; goto END; } END: if (fpout != stdout) fclose(fpout); return exit_status; }