/***************************************************************************** Function: ar1.c Autoregressive function of order 1 Description: Parameters: ar1 [phi] [x0] [ZSigma] [seed] [number] Return: a list of the x1...xN values *****************************************************************************/ #include #include #include "random.h" float rannorm(long *); int main(int argc, char *argv[]) { long seed; unsigned long i,n; double phi,x,stdev; if (argc >5) { n = atof(argv[5]); } else { n=10; } if (argc > 4) { seed = -atol(argv[4]); } else { seed = -1964; } if ( argc >3 ) { stdev = atof(argv[3]); } else { stdev = 1; } if (argc > 2) { x = atof(argv[2]); } else { x = 0; } if (argc > 1) { phi = atof(argv[1]); } else { phi = 0.1; } printf("# ar1.c [phi] [x0] [zsigma] [seed] [number]\n"); printf("# generates data from an AR(1) process: X(t)=phi * X(t-1) + Zt\n"); printf("# dforrest@virginia.edu 1997\n"); printf("# AR(1) phi=%g X0=%g Zsigma=%g seed=%li n=%li\n",phi,x,stdev,-seed,n); for (i=1;i<=n ;i++ ) { x = phi * x + rannorm(&seed)*stdev; printf("%g\n",x); } return 0; }