% integrates the Lorenz model
% we use ode45, which is a Runge-Kutta method (basically a fancy Euler method)
% for Matlab reasons the ODE function itself needs to be defined at the end of the script

% DEFINE PARAMETERS
Pr = 10;
b = 8/3;
r = 28;

% set up start and end times of the integration
tstart = 0;
tend = 200;

% timestep 
dt = 0.002;

% initial condition 
x_0 = [0.01, 0.01, 0.01];

% INTEGRATE AND PLOT
t = linspace(tstart,tend,floor((tend-tstart)/dt));

[t_out,x] = ode45(@(t,x) odefcn(t,x,Pr,b,r),t,x_0);

figure
plot(t_out,x(:,1));
xlabel('Time')
ylabel('x')

% DEFINE ODE FUNCTION
function dxdt = odefcn(t,x,Pr,b,r)
    dxdt = zeros(3,1);
    dxdt(1) = Pr*x(2)-Pr*x(1);
    dxdt(2) = -x(1)*x(3)+r*x(1)-x(2);
    dxdt(3) = x(1)*x(2)-b*x(3);
end

