%integrates the lorenz equations (found in lorenz.m)
%over prescribed time span and plots time series and attractor.
clear all
close all

%define parameters
%good values for strange attractor are
%sigma=10, r=45, b=8/3
p.sigma=10;
p.r=23.9653125;%23.9653125 %23.965250
p.b=8/3;

startxyz=[0.5;0.5;0.5]; %set initial conditions
tspan=[0,500]; %set time span for integration

[t_all,outxyz]=ode45(@lorenz,tspan,startxyz,[],p); %integrate over tspan

t=t_all(end-2000:end);
x=outxyz(end-2000:end,1);
y=outxyz(end-2000:end,2);
z=outxyz(end-2000:end,3);

% t=t_all;
% x=outxyz(:,1);
% y=outxyz(:,2);
% z=outxyz(:,3);

%plot the time series for each variable
figure
plot(t,x,t,y,t,z)
legend('x','y','z');
xlabel('time')
ylabel('variables')

figure
plot(t,x)
xlabel('time')
ylabel('x')


%plot 2D projection of attractor
figure
plot(x,z)
xlabel('x')
ylabel('z')

%plot 3D attractor
figure
plot3(x,y,z)
xlabel('x')
ylabel('y')
zlabel('z')