/* nag_multi_normal (g01hbc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. * Mark 7, revised. * */ #include #include #include #include #include #define SIGMA(I, J) sigma[((I) -1)*n + (J) -1] int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, j, maxpts, n; char nag_enum_arg[40]; double *a = 0, *b = 0, *mean = 0, prob, *sigma = 0, tol; Nag_TailProbability tail; NagError fail; 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_multi_normal (g01hbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld %lf %s", &n, &tol, nag_enum_arg); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ tail = (Nag_TailProbability) nag_enum_name_to_value(nag_enum_arg); if (!(a = NAG_ALLOC(n, double)) || !(b = NAG_ALLOC(n, double)) || !(mean = NAG_ALLOC(n, double)) || !(sigma = NAG_ALLOC(n*n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &mean[j - 1]); for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &SIGMA(i, j)); if (tail == Nag_Central || tail == Nag_UpperTail) for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &a[j - 1]); if (tail == Nag_Central || tail == Nag_LowerTail) for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &b[j - 1]); maxpts = 2000; /* nag_multi_normal (g01hbc). * Computes probabilities for the multivariate Normal * distribution */ prob = nag_multi_normal(tail, n, a, b, mean, sigma, n, tol, maxpts, &fail); if (fail.code == NE_NOERROR || fail.code == NE_ACC || fail.code == NE_ROUND_OFF) { fprintf(fpout, "\nMultivariate Normal probability = %6.4f\n", prob); } else { fprintf(fpout, "Error from nag_multi_normal (g01hbc).\n%s\n", fail.message); exit_status = 1; goto END; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); if (b) NAG_FREE(b); if (mean) NAG_FREE(mean); if (sigma) NAG_FREE(sigma); return exit_status; }