/* nag_zero_cont_func_cntin_rcomm (c05axc) Example Program. * * Copyright 2007 Numerical Algorithms Group. * * Mark 9, 2009. */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpout; /* Scalars */ Integer exit_status = 0; double fx, tol, x, scal, i; Integer ind; Nag_ErrorControl ir; /* Arrays */ double c[26]; 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_cntin_rcomm (c05axc) Example Program Results\n"); scal = sqrt(nag_machine_precision); ir = Nag_Mixed; for (i = 3; i <= 4; i++) { tol = pow(10.0, -i); fprintf(fpout, "\ntol = %13.4e\n\n", tol); x = 1.0; ind = 1; /* nag_zero_cont_func_cntin_rcomm (c05axc). * Locates a zero of a continuous function. * Reverse communication. */ while (ind != 0) { nag_zero_cont_func_cntin_rcomm(&x, fx, tol, ir, scal, c, &ind, &fail); if (ind != 0) { fx = x - exp(-x); } } if (fail.code == NE_NOERROR) { fprintf(fpout, "Root is %14.5f\n", x); } else { fprintf(fpout, "Error from nag_zero_cont_func_cntin_rcomm (c05axc) %s\n", fail.message); if (fail.code == NE_CONTIN_PROB_NOT_SOLVED || fail.code == NE_FINAL_PROB_NOT_SOLVED) { fprintf( fpout, "Final value = %14.5f, theta = %10.2f\n", x, c[4]); } exit_status = 1; goto END; } } END: if (fpout != stdout) fclose(fpout); return exit_status; }