

%==========================================================================
%REU Tutorial:  (Example Four)
%
%ode_example.m
%
%Solving Ordinary Differential equations.  Plotting the results
%
%Dependency: This program depends on the file 'lorenzField.m'
%==========================================================================



clear
format long


%number of time discretizations
numSteps = 5000

tspan = linspace(0, 50, numSteps);  %Time axis
y0 = [0.5; 1.0; 0.2]                %initial conditions
sigma = 10                          %Parameters
beta = 8/3
%rho = 28
rho = 99.96;

%Integraton:
options=odeset('RelTol',1e-12,'AbsTol',1e-8);
[t,y] = ode45('lorenzField', tspan, y0, options, flag, sigma, rho, beta);


%Save Data:
save('lorenz.mat');

%To recover data type
%>> load lorenz.mat


%State Variable Plots: 
figure
hold on
plot(t(:), y(:,1), 'r')
plot(t(:), y(:,2), 'b')
plot(t(:), y(:,3), 'g')
xlabel('time axis','FontSize',8)
ylabel('state variables','FontSize',8)
title('time series for the Lorenz Systems','FontSize',10)
h = legend('x', 'y', 'z', 3)

%Phase Space Plot
figure
hold on
plot3(y(1000:numSteps ,1), y(1000:numSteps ,2), y(1000:numSteps ,3)) 
xlabel('x-axis','FontSize',8)
ylabel('y-axis','FontSize',8)
zlabel('z-axis','FontSize',8)
title('State Space of the Lorenz Systems','FontSize',10)




