ar1.m (587B)
1 % AR1.m ar1(rho,T,N,const,stddev,trend) 2 % Generates N AR(1) series of length T with root rho 3 % 4 % Note: StdDev, const, and trend can be scalar or Nx1 5 6 function data=ar1(rho,T,N,const,stddev,trend); 7 8 if exist('trend')~=1; 9 trend=0; 10 end; 11 12 13 if length(stddev)~=1; stddev=kron(ones(T+1,1),stddev'); end; 14 if length(const)~=1; const=const'; end; 15 if length(trend)~=1; trend=kron((1:T)',trend'); 16 else; trend=trend*kron((1:T)',ones(1,N)); end; 17 18 19 e=randn(T+1,N).*stddev; 20 data=e(1,:); 21 for i=2:T+1; 22 data=[data; const+rho*data(i-1,:)+e(i,:)]; 23 end; 24 data(1,:)=[]; 25 data=data+trend;