% Integrate the Lorenz equations.

% Lorenz, E. N., 1963, Deterministic nonperiodic flow, Journal of the
% Atmospheric Sciences, 20, 130-141.

% Equations:
% \dot{x}(1) = -\sigma*x(1) + \sigma*x(2)
% \dot{x}(2) = -x(1)*x(3) + r*x(1) - x(2)
% \dot{x}(3) =  x(1)*x(2) - b*x(3)

% Written by Jim Hansen, Feb 2003 for 12.990 students

% Specify the dimension of the system
dim = 3;

% Specify the initial conditions
x = [10 20 30];

% Specify the parameter values (sigma, r, and b)
par = [10 28 8/3];

% Specify the integration step size
h = 0.01;

% 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('derivsL63',x,par,h,dim);
 x=xout;
end

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

% Make a pretty picture
figure;plot3(state(:,3),state(:,2),state(:,1)'.');
title('The Lorenz attractor');
xlabel('z');ylabel('y');zlabel('x');

print -djpeg90 L63.jpg
