/* nag_rngs_multi_normal (g05lzc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. * Mark 7b revised, 2004. */ #include #include #include #include int main(void) { /* Scalars */ Integer igen, j, m; Integer exit_status=0; Integer pdc; NagError fail; Nag_OrderType order; /* Arrays */ double *c=0, *r=0, *x=0, *xmu=0; Integer iseed[4]; #ifdef NAG_COLUMN_MAJOR #define C(I,J) c[(J-1)*pdc + I - 1] order = Nag_ColMajor; #else #define C(I,J) c[(I-1)*pdc + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); Vprintf("nag_rngs_multi_normal (g05lzc) Example Program Results\n\n"); m = 2; /* Allocate memory */ if ( !(c = NAG_ALLOC(m * m, double)) || !(r = NAG_ALLOC((m+1)*(m+2)/2, double)) || !(x = NAG_ALLOC(m, double)) || !(xmu = NAG_ALLOC(m, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } #ifdef NAG_COLUMN_MAJOR pdc = m; #else pdc = m; #endif /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 42344; iseed[3] = 742355; /* igen identifies the stream. */ igen = 1; /* nag_rngs_init_repeatable (g05kbc). * Initialize seeds of a given generator for random number * generating functions (that pass seeds explicitly) to give * a repeatable sequence */ nag_rngs_init_repeatable(&igen, iseed); C(1, 1) = 2.0; C(2, 1) = 1.0; C(1, 2) = 1.0; C(2, 2) = 3.0; xmu[0] = 1.0; xmu[1] = 2.0; /* Set up reference vector and generate numbers */ /* nag_rngs_multi_normal (g05lzc). * Generates a vector of random numbers from a multivariate * Normal distribution, seeds and generator number passed * explicitly */ nag_rngs_multi_normal(order, 0, m, xmu, c, m, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_rngs_multi_normal (g05lzc).\n%s\n", fail.message); exit_status = 1; goto END; } for (j = 0; j < m; ++j) Vprintf("%10.4f\n", x[j]); /* Generate numbers */ /* nag_rngs_multi_normal (g05lzc), see above. */ nag_rngs_multi_normal(order, 2, m, xmu, c, m, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_rngs_multi_normal (g05lzc).\n%s\n", fail.message); exit_status = 1; goto END; } for (j = 0; j < m; ++j) Vprintf("%10.4f\n", x[j]); END: if (c) NAG_FREE(c); if (r) NAG_FREE(r); if (x) NAG_FREE(x); if (xmu) NAG_FREE(xmu); return exit_status; }