/* nag_prob_lin_chi_sq (g01jdc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(void) { /* Scalars */ double c, d, prob; Integer exit_status, i, n; /* Arrays */ char *method=0; double *rlam=0; Nag_LCCMethod method_enum; NagError fail; INIT_FAIL(fail); exit_status = 0; Vprintf("nag_prob_lin_chi_sq (g01jdc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); n = 10; /* Allocate memory */ if ( !(method = NAG_ALLOC(2, char)) || !(rlam = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vscanf(" ' %1s '%lf%lf%*[^\n] ", method, &d, &c); for (i = 1; i <= n; ++i) Vscanf("%lf", &rlam[i - 1]); Vscanf("%*[^\n] "); if (!(strcmp(method, "P"))) method_enum = Nag_LCCPan; else if (!(strcmp(method, "I"))) method_enum = Nag_LCCImhof; else if (!(strcmp(method, "D"))) method_enum = Nag_LCCDefault; else { Vprintf("The character `method' is invalid\n"); exit_status = -1; goto END; } /* nag_prob_lin_chi_sq (g01jdc). * Computes lower tail probability for a linear combination * of (central) chi^2 variables */ nag_prob_lin_chi_sq(method_enum, n, rlam, d, c, &prob, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_prob_lin_chi_sq (g01jdc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("Values of lambda "); for (i = 1; i <= n; ++i) { Vprintf("%6.2f", rlam[i - 1]); Vprintf(i%10 == 0 || i == 10 ?"\n":" "); } Vprintf(" Value of D %6.2f\n", d); Vprintf(" Value of C %6.2f\n\n", c); Vprintf(" Probability = %10.4f\n", prob); END: if (method) NAG_FREE(method); if (rlam) NAG_FREE(rlam); return exit_status; }