% integrates the Roessler 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
a = 0.2;
b = 0.2;
c = 5.7;

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

% timestep 
dt = 0.01;

% initial condition 
x_0 = [0.0, 5.7, 0.05];

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

[t_out,x] = ode45(@(t,x) odefcn(t,x,a,b,c),t,x_0);

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

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

