/* nag_rngs_orthog_matrix (g05qac) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ Integer i, igen, j, m, n; Integer exit_status = 0; Integer pda; NagError fail; Nag_OrderType order; /* Arrays */ double *a = 0; Integer iseed[4]; #ifdef NAG_COLUMN_MAJOR #define A(I, J) a[(J-1)*pda + I - 1] order = Nag_ColMajor; #else #define A(I, J) a[(I-1)*pda + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); printf("nag_rngs_orthog_matrix (g05qac) Example Program Results\n\n"); m = 4; n = 4; /* Allocate memory */ if (!(a = NAG_ALLOC(m * n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } #ifdef NAG_COLUMN_MAJOR pda = m; #else pda = n; #endif /* 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_orthog_matrix (g05qac). * Computes a random orthogonal matrix */ nag_rngs_orthog_matrix(order, Nag_RightSide, Nag_InitializeI, m, n, a, pda, igen, iseed, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_rngs_orthog_matrix (g05qac).\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 1; i <= 4; ++i) { printf("%1s", ""); for (j = 1; j <= 4; ++j) { printf("%9.3f", A(i, j)); printf("%s", j%4 == 0 || j == 4?"\n":" "); } } END: if (a) NAG_FREE(a); return exit_status; }