/* nag_multi_normal (g01hbc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. * Mark 7, revised. * */ #include #include #include #include #define SIGMA(I,J) sigma[((I)-1)*n + (J)-1] int main(void) { Integer exit_status=0, i, j, maxpts, n; NagError fail; Nag_TailProbability tail_enum; char tail[2]; double *a=0, *b=0, *mean=0, prob, *sigma=0, tol; INIT_FAIL(fail); Vprintf("nag_multi_normal (g01hbc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld %lf %s", &n, &tol, tail); if (!(a = NAG_ALLOC(n, double)) || !(b = NAG_ALLOC(n, double)) || !(mean = NAG_ALLOC(n, double)) || !(sigma = NAG_ALLOC(n*n, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } if (*tail == 'L') tail_enum = Nag_LowerTail; else if (*tail == 'U') tail_enum = Nag_UpperTail; else if (*tail == 'C') tail_enum = Nag_Central; else tail_enum = (Nag_TailProbability)-999; for (j = 1; j <= n; ++j) Vscanf("%lf", &mean[j - 1]); for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) Vscanf("%lf", &SIGMA(i,j)); if (tail_enum == Nag_Central || tail_enum == Nag_UpperTail) for (j = 1; j <= n; ++j) Vscanf("%lf", &a[j - 1]); if (tail_enum == Nag_Central || tail_enum == Nag_LowerTail) for (j = 1; j <= n; ++j) Vscanf("%lf", &b[j - 1]); maxpts = 2000; /* nag_multi_normal (g01hbc). * Computes probabilities for the multivariate Normal * distribution */ prob = nag_multi_normal(tail_enum, n, a, b, mean, sigma, n, tol, maxpts, &fail); if (fail.code == NE_NOERROR || fail.code == NE_ACC || fail.code == NE_ROUND_OFF ) { Vprintf("%s %6.4f\n", "\nMultivariate Normal probability = ", prob); } else { Vprintf("Error from nag_multi_normal (g01hbc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (a) NAG_FREE(a); if (b) NAG_FREE(b); if (mean) NAG_FREE(mean); if (sigma) NAG_FREE(sigma); return exit_status; }