/* nag_rngs_corr_matrix (g05qbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ double eps; Integer i, igen, j, n; Integer exit_status=0; Integer pdc; NagError fail; Nag_OrderType order; /* Arrays */ double *c=0, *d=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_corr_matrix (g05qbc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%*[^\n] ", &n); /* Allocate memory */ if ( !(c = NAG_ALLOC(10 * 10, double)) || !(d = NAG_ALLOC(10, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } #ifdef NAG_COLUMN_MAJOR pdc = n; #else pdc = n; #endif if (n <= 10) { for (i = 0; i < n; ++i) { Vscanf("%lf", &d[i]); } Vscanf("%*[^\n] "); eps = 1e-4; /* igen identifies the stream. */ igen = 1; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 423446; iseed[3] = 742355; /* 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); /* nag_rngs_corr_matrix (g05qbc). * Computes a random correlation matrix */ nag_rngs_corr_matrix(order, n, d, c, pdc, eps, igen, iseed, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_rngs_corr_matrix (g05qbc).\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 1; i <= n; ++i) { for (j = 1; j <= n; ++j) { Vprintf("%9.3f%s", C(i,j), j%3 == 0 || j == n ?"\n":" "); } } } END: if (c) NAG_FREE(c); if (d) NAG_FREE(d); return exit_status; }