/* nag_bessel_zeros (s17alc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * NAG C Library * * Mark 6, 2000. * Mark 7, revised, 2001. * */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; #define NMAX 100 Integer exit_status = 0, i, mode, n; NagError fail; double a, rel, *x = 0; 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_bessel_zeros (s17alc) Example Program Results\n\n"); if (!(x = NAG_ALLOC(NMAX, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; } /* nag_machine_precision (x02ajc). * The machine precision */ rel = sqrt(X02AJC); fscanf(fpin, "%lf %ld %ld", &a, &n, &mode); /* nag_bessel_zeros (s17alc). * Zeros of Bessel functions J_alpha(x), (J_alpha')(x), * Y_alpha(x) or (Y_alpha')(x) */ nag_bessel_zeros(a, n, mode, rel, x, &fail); if (fail.code == NE_NOERROR) { fprintf(fpout, " a n mode\n"); fprintf(fpout, " %4.1f%3ld%6ld\n\n", a, n, mode); if (mode == 1) fprintf(fpout, "Leading n positive zeros of J\n"); else if (mode == 2) fprintf(fpout, "Leading n positive zeros of Y\n"); else if (mode == 3) { if (a == 0.0) fprintf(fpout, "Leading n non-negative zeros of J'\n"); else fprintf(fpout, "Leading n positive zeros of J'\n"); } else if (mode == 4) fprintf(fpout, "Leading n positive zeros of Y'\n\n"); for (i = 0; i <= n-1; ++i) fprintf(fpout, " x = %13.4e\n", x[i]); fprintf(fpout, "\n"); } else { fprintf(fpout, "Error from nag_bessel_zeros (s17alc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); return exit_status; }