% Integrate the Lorenz '95 equations.

% Lorenz, E. and K. Emanuel, 1998.  Optimal Sites for Supplementary
% Weather Observations: Simulation with a Small Model, JAS, 55, 399-414.

% Equations
% \dot{x}_i = -x_{i-2}*x_{i-1} + x_{i-1}*x_{i+1} - x_{i} + f

% Written by Jim Hansen, Feb 2003 for 12.990 students

% Specify the dimension of the system
dim = 10;

% Specify the parameter values (f)
par(1:dim)=8;

% Specify the initial conditions
for i=1:dim;x(i)=par(i)+randn;end

% Specify the integration step size
h = 0.05;

% Specify the length of integration
steps = 2^12;

% Integrate the equations over length steps to remove any transient behavior
for i=1:steps
 xout=step_it('derivsL95',x,par,h,dim);
 x=xout;
end

% Integrate the equations over length steps and record state for plotting
for i=1:steps
 time(i)=i*h;
 xout=step_it('derivsL95',x,par,h,dim);
 state(i,:)=xout;
 x=xout;
end

% Make a pretty picture

figure;plot(time(1:1000),state(1:1000,1))
title('A 1D trajectory from the Lorenz 95 attractor');
xlabel('time');ylabel('x(1)');

print -djpeg90 L95.jpg
