/* nag_bessel_j_alpha (s18ekc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * NAG C Library * * Mark 6, 2000. * Mark 8 revised, 2004. * */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Complex *b = 0; Integer exit_status = 0, i, nl; NagError fail; double a, alpha, d, x; 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_j_alpha (s18ekc) Example Program Results\n"); if (!(b = NAG_ALLOC(101, Complex))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } while (fscanf(fpin, "%lf %lf %ld%*[^\n]", &x, &a, &nl) != EOF) { fprintf(fpout, " x a nl\n"); fprintf(fpout, "%4.1f %4.1f %6ld\n\n", x, a, nl); /* nag_bessel_j_alpha (s18ekc). * Bessel functions J_(alpha + n - 1)(x) or * J_(alpha - n + 1)(x) for real x != 0, non-negative * alpha < 1 and n = 1 , 2 , ... , |N| + 1 */ nag_bessel_j_alpha(x, a, nl, b, &fail); if (fail.code == NE_NOERROR) { fprintf(fpout, " Requested values of J_alpha(X)\n\n"); alpha = a; fprintf(fpout, " alpha J_alpha(X)\n"); for (i = 0; i < ABS(nl) + 1; ++i) { fprintf(fpout, " %13.4e (%13.4e, %13.4e)\n", alpha, b[i].re, b[i].im); d = (double) nl; alpha += SIGN(1.0, d); } } else { fprintf(fpout, "Error from nag_bessel_j_alpha (s18ekc).\n%s\n", fail.message); exit_status = 1; goto END; } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (b) NAG_FREE(b); return exit_status; }