/* nag_arma_time_series (g05hac) Example Program. * * Copyright 1992 Numerical Algorithms Group. * * Mark 3, 1992. * Mark 8 revised, 2004. */ #include #include #include #include #define NA 3 #define NB 2 #define NR 20 #define NW 10 int main(void) { Nag_Boolean start; Integer exit_status=0, i, ip, iq, n, seed=0; NagError fail; double mean, *phi=0, *ref=0, *theta=0, vara, *w=0; INIT_FAIL(fail); Vprintf("nag_arma_time_series (g05hac) Example Program Results\n\n"); /* nag_random_init_repeatable (g05cbc). * Initialize random number generating functions to give * repeatable sequence */ nag_random_init_repeatable(seed); ip = 2; iq = 0; n = NW; mean = 0.0; vara = 2.0; if ( !( phi = NAG_ALLOC(NA, double)) || !( theta = NAG_ALLOC(NB, double)) || !( w = NAG_ALLOC(NW, double)) || !( ref = NAG_ALLOC(NR, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Generate an ARMA series with 5 terms */ phi[0] = 0.4; phi[1] = 0.2; start = Nag_TRUE; /* nag_arma_time_series (g05hac). * ARMA time series of n terms */ nag_arma_time_series(start, ip, iq, phi, theta, mean, vara, (Integer)5, w, ref, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_arma_time_series (g05hac).\n%s\n", fail.message); exit_status = 1; goto END; } /* Add further 5 terms to the previous series*/ start = Nag_FALSE; /* nag_arma_time_series (g05hac), see above. */ nag_arma_time_series(start, ip, iq, phi, theta, mean, vara, (Integer)5, &w[5], ref, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_arma_time_series (g05hac).\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 0; i < n; ++i) Vprintf("%12.4f \n", w[i]); END: if (phi) NAG_FREE(phi); if (theta) NAG_FREE(theta); if (w) NAG_FREE(w); if (ref) NAG_FREE(ref); return exit_status; }