/* nag_tsa_arma_roots (g13dxc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include int main(void) { /* Scalars */ Integer exit_status, i, ip, k, npar; NagError fail; /* Arrays */ double *par = 0, *ri = 0, *rmod = 0, *rr = 0; INIT_FAIL(fail); exit_status = 0; Vprintf("nag_tsa_arma_roots (g13dxc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%ld%*[^\n] ", &k, &ip); if (k > 0 && ip > 0) { /* Allocate arrays */ if ( !(par = NAG_ALLOC(k*k*ip, double)) || !(ri = NAG_ALLOC(k*ip, double)) || !(rmod = NAG_ALLOC(k*ip, double)) || !(rr = NAG_ALLOC(k*ip, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } /* Read the AR (or MA) parameters */ npar = ip * k * k; for (i = 1; i <= npar; ++i) Vscanf("%lf", &par[i-1]); Vscanf("%*[^\n] "); /* nag_tsa_arma_roots (g13dxc). * Calculates the zeros of a vector autoregressive (or * moving average) operator */ nag_tsa_arma_roots(k, ip, par, rr, ri, rmod, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tsa_arma_roots (g13dxc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf(" Eigenvalues Moduli\n"); Vprintf(" ----------- ------\n"); for (i = 1; i <= k * ip; ++i) { if (ri[i-1] >= 0.0) Vprintf("%10.3f + %6.3f i %8.3f\n", rr[i-1], ri[i-1], rmod[i-1]); else Vprintf("%10.3f - %6.3f i %8.3f\n", rr[i-1], -ri[i-1], rmod[i-1]); } } else Vprintf(" Either k or ip is out of range\n"); END: if (par) NAG_FREE(par); if (ri) NAG_FREE(ri); if (rmod) NAG_FREE(rmod); if (rr) NAG_FREE(rr); return exit_status; }