/* nag_rngs_multi_normal(g05lzc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer igen, j, m, nr; 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("g05lzc Example Program Results\n\n"); m = 2; nr = (m+1)*(m+2)/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; g05kbc(&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 */ g05lzc(order, 0, m, xmu, c, m, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from 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 */ g05lzc(order, 2, m, xmu, c, m, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from 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; }