/* nag_real_polygamma (s14aec) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * NAG C Library * * Mark 6, 2000. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, k; NagError fail; double x, y; INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fprintf(fpout, "nag_real_polygamma (s14aec) Example Program Results\n\n"); fprintf(fpout, " x k (d^k/dx^k)psi(x)\n"); while (fscanf(fpin, "%lf %ld%*[^\n]", &x, &k) != EOF) { /* nag_real_polygamma (s14aec). * Derivative of the psi function psi(x) */ y = nag_real_polygamma(x, k, &fail); if (fail.code == NE_NOERROR) fprintf(fpout, "%5.1f %5ld %13.4e\n", x, k, y); else { fprintf(fpout, "Error from nag_real_polygamma (s14aec).\n%s\n", fail.message); exit_status = 1; goto END; } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); return exit_status; }