% This program plots phase diagrams for the Lorenz equations.
% x' = -ax + ay
% y' = bx - y - xz
% z' = -cz + xy
%
% Since the Lorenz equations are not exactly solvable, we numerically
% integrate them using linear approximations.
% This program calls for the size of the discrete time intervals, the total
% number of intervals, a starting point, and a set of parameters for the
% Lorenz equations.
% It then plots the solutions in 3-D and then plots the x,y, and z components
% on separate graphs.


step=input('Enter the step size: ');
t=input('Enter the total number of steps: ');
x=input('Enter the starting point [x,y,z]: ');
a=input('Enter the parameters [a,b,c] ([10,28,8/3] is the Lorenz model): ');

r=zeros(3,t+1);
r(:,1) = x';

for i=1:t
r(:,i+1) = r(:,i) + step.*[-a(1).*r(1,i) + a(1).*r(2,i); a(2).*r(1,i) - (r(2,i) + r(1,i).*r(3,i)); (-a(3))*r(3,i) + r(1,i).*r(2,i)];
end;

plot3(r(1,:),r(2,:),r(3,:))
figure
plot(r(1,:))
figure
plot(r(2,:))
figure
plot(r(3,:))
