% integrates the Lorenz model and calculates correlation dimensions

% DEFINE PARAMETERS - DON'T CHANGE
Pr = 10;
b = 8/3;
r = 28;

% PARAMETERS YOU CAN CHANGE FOR CORRELATION DIMENSION CALCULATIONS
% set up start and end times of the integration
tstart = 0;
tend = 2000;

% timestep 
dt = 0.2;

% embedding dimension
embedding_dimension = 6;

% 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')

correlationDimension(x(:,1),embedding_dimension);

% 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
