/* nag_rngs_matrix_multi_students_t (g05lxc) Example Program. * * Copyright 2004 Numerical Algorithms Group. * * Mark 8, 2004. */ #include #include #include #include int main(void) { /* Scalars */ Integer df, exit_status, i, igen, j, lr, m, mode, n, pdc, pdx; /* Arrays */ double *c=0, *r=0, *x=0, *xmu=0; Integer iseed[4]; /* Nag types */ NagError fail; Nag_OrderType order; #ifdef NAG_COLUMN_MAJOR #define C(I, J) c[(J-1)*pdc + I - 1] #define X(I, J) x[(J-1)*pdx + I - 1] order = Nag_ColMajor; #else #define C(I, J) c[(I-1)*pdc + J - 1] #define X(I, J) x[(I-1)*pdx + J - 1] order = Nag_RowMajor; #endif #define XMU(I) xmu[I - 1] INIT_FAIL(fail); exit_status = 0; /* Set the number of variables and variates */ m = 4; n = 10; lr = m * (m + 1) + 2; pdc = m; pdx = m; /* Allocate memory */ if ( !(c = NAG_ALLOC(pdc * pdc, double)) || !(r = NAG_ALLOC(lr, double)) || !(x = NAG_ALLOC(pdx * n, double)) || !(xmu = NAG_ALLOC(m, double) )) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vprintf("nag_rngs_matrix_multi_students_t (g05lxc) Example Program Results" "\n\n"); /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 42344; iseed[3] = 742355; /* Choose the random generator to use */ igen = 1; /* Initialise the random generator */ /* 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); /* Input the upper triangle portion of the covariance matrix */ C(1, 1) = 1.69; C(1, 2) = 0.39; C(1, 3) = -1.86; C(1, 4) = 0.07; C(2, 2) = 98.01; C(2, 3) = -7.07; C(2, 4) = -0.71; C(3, 3) = 11.56; C(3, 4) = 0.03; C(4, 4) = 0.01; /* Input the means */ XMU(1) = 1.0; XMU(2) = 2.0; XMU(3) = -3.0; XMU(4) = 0.0; /* Set the mode */ mode = 0; /* Set the degrees of freedom */ df = 10; /* Set up reference vector and generate n numbers */ /* nag_rngs_matrix_multi_students_t (g05lxc). * Generates a matrix of random numbers from a multivariate * Student's t-distribution, seeds and generator passed * explicitly */ nag_rngs_matrix_multi_students_t(order, mode, df, m, xmu, c, pdc, n, x, pdx, igen, iseed, r, lr, &fail); /* Display the results */ for (i=1; i<=n; ++i) { for (j=1; j<=m; ++j) { Vprintf("%10.4f ", X(i,j)); } Vprintf("\n"); } END: if (c) NAG_FREE(c); if (r) NAG_FREE(r); if (x) NAG_FREE(x); if (xmu) NAG_FREE(xmu); return exit_status; }