function RoesslerDefect
%ROESSLERDEFECT  Defect in Roessler equations.
%  Chaotic values of parameters

tspan = [0 300];
y0 = [0; 1; 1];

% solve the problem using ODE45
opts = odeset('RelTol',1.0e-10,'AbsTol',[1.0e-11,1.0e-11,1.0e-11]);
Roesslersol = ode45(@f,tspan,y0,opts);
tref = RefineMesh( Roesslersol.x );
[y,dy] = deval( Roesslersol, tref );
residual = zeros( size(y) );
numt = length(tref);
for i=1:numt,
    residual(:,i) = dy(:,i) - f(tref(i),y(:,i));
end;
max(max(abs(residual)))
figure(1), plot3( Roesslersol.y(1,:), Roesslersol.y(2,:), Roesslersol.y(3,:), 'k' );
set(gca,'fontsize',16)
figure(2), semilogy( tref, abs( residual ), 'k.' )
set(gca,'fontsize',16)
h = diff( Roesslersol.x );
figure(3), semilogy( Roesslersol.x(2:end), h, 'k.' )
set(gca,'fontsize',16)

% ---------------------------------------
function dydt = f(t,y)
a = 0.1;
b = 0.1;
c = 14;  % Wikipedia values
dydt = [   -y(2)-y(3) 
           y(1)+a*y(2) 
           b + y(3)*(y(1)-c) ];