/* nag_prob_lin_non_central_chi_sq (g01jcc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Initialized data */ Integer maxit = 500; double tol = 1e-4; /* Scalars */ double c, p, pdf; Integer exit_status, i, n; NagError fail; /* Arrays */ double *a = 0, *rlamda = 0; Integer *mult = 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); exit_status = 0; fprintf(fpout, "nag_prob_lin_non_central_chi_sq (g01jcc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fprintf(fpout, "\n A MULT RLAMDA\n"); while (fscanf(fpin, "%ld%lf%*[^\n] ", &n, &c) != EOF) { /* Allocate memory */ if (!(a = NAG_ALLOC(n, double)) || !(rlamda = NAG_ALLOC(n, double)) || !(mult = NAG_ALLOC(n, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } fprintf(fpout, "\n"); for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &a[i - 1]); fscanf(fpin, "%*[^\n] "); for (i = 1; i <= n; ++i) fscanf(fpin, "%ld", &mult[i - 1]); fscanf(fpin, "%*[^\n] "); for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &rlamda[i - 1]); fscanf(fpin, "%*[^\n] "); /* nag_prob_lin_non_central_chi_sq (g01jcc). * Computes probability for a positive linear combination of * chi^2 variables */ nag_prob_lin_non_central_chi_sq(a, mult, rlamda, n, c, &p, &pdf, tol, maxit, &fail); if (fail.code == NE_NOERROR || fail.code == NE_ACCURACY || fail.code == NE_PROB_BOUNDARY) { for (i = 1; i <= n; ++i) fprintf(fpout, " %10.2f%6ld%9.2f\n", a[i - 1], mult[i - 1], rlamda[i - 1]); fprintf(fpout, "c = %6.2f Prob = %6.4f\n", c, p); } else { fprintf(fpout, "Error from nag_normal_scores_exact (g01dac).\n%s\n", fail.message); exit_status = 1; goto END; } if (a) NAG_FREE(a); if (rlamda) NAG_FREE(rlamda); if (mult) NAG_FREE(mult); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); if (rlamda) NAG_FREE(rlamda); if (mult) NAG_FREE(mult); return exit_status; }