/* nag_rngs_arma_time_series(g05pac) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ double avar, var, xmean; Integer i, igen, ip, iq, n, nr; Integer exit_status=0; NagError fail; /* Arrays */ double *phi=0, *r=0, *theta=0, *x=0; Integer iseed[4]; INIT_FAIL(fail); Vprintf("g05pac Example Program Results\n\n"); ip=2; iq=0; n=10; nr=ip+iq+5+ip; /* allocate memory */ if ( !(phi = NAG_ALLOC(ip, double)) || !(r = NAG_ALLOC(nr, double)) || !(theta = NAG_ALLOC(1, double)) || !(x = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Set the ARMA model parameters */ xmean = 0.0; phi[0] = 0.4; phi[1] = 0.2; avar = 1.0; /* Initialise the seed to a repeatable sequence */ iseed[0] = 1762543; iseed[1] = 9324783; iseed[2] = 4234401; iseed[3] = 742355; /* igen identifies the stream. */ igen = 1; g05kbc(&igen, iseed); /* Set up the reference vector */ g05pac(0, xmean, ip, phi, iq, theta, avar, &var, n, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g05pac.\n%s\n", fail.message); exit_status = 1; goto END; } /* Generate a sample of 10 observations */ g05pac(1, xmean, ip, phi, iq, theta, avar, &var, n, x, igen, iseed, r, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g05pac.\n%s\n", fail.message); exit_status = 1; goto END; } for (i = 0; i < n; ++i) { Vprintf("%12.4f\n", x[i]); } END: if (phi) NAG_FREE(phi); if (r) NAG_FREE(r); if (theta) NAG_FREE(theta); if (x) NAG_FREE(x); return exit_status; }