/* nag_prob_non_central_chi_sq (g01gcc) Example Program. * * Copyright 1999 Numerical Algorithms Group. * * Mark 6a revised, 2001. */ #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, max_iter; NagError fail; double df, lambda, prob, tol, 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); fprintf(fpout, "nag_prob_non_central_chi_sq (g01gcc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fprintf(fpout, "\n x df lambda prob\n\n\n"); tol = 5e-6; max_iter = 50; while ((fscanf(fpin, " %lf %lf %lf %*[^\n] ", &x, &df, &lambda)) != EOF) { /* nag_prob_non_central_chi_sq (g01gcc). * Computes probabilities for the non-central chi^2 * distribution */ prob = nag_prob_non_central_chi_sq(x, df, lambda, tol, max_iter, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_prob_non_central_chi_sq (g01gcc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "%8.3f %8.3f %8.3f %8.4f\n", x, df, lambda, prob); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); return exit_status; }