echo on
% Script to solve y' = x^2 + y^2, y(0)=1
% on 0 <= x <= 1/2
%
% with a crude test for accuracy
%
[x,y] = ode45('singer',[0,0.5],1);
size(x)
figure(1)
plot(x,y,'.')
%
% Now tighten the tolerances and solve again
%
tighter = odeset('reltol',1.e-8,'abstol',1.e-8);
% Pass in the x-values we want the solution
% evaluated at, namely the same x-values produced
% by the crude solution
[xc,yc] = ode45('singer',x,1,tighter);
size(xc)
err = yc-y;
figure(2)
semilogy(x,abs(err),'.')
% We see that the maximum error is about 1.e-6
% (but growing across the interval)
%
% Let us try to solve the problem on a larger
% interval.
[xt,yt] = ode45('singer',[0,0.98],1,tighter);
n = length(xt)
figure(3)
semilogy(xt,yt)
% We see that the solution is growing rapidly
% near the right endpoint.
%
% Let us look at the step sizes:
delx = xt(2:n) - xt(1:n-1);
figure(4)
semilogy( xt(2:n), delx, '.' )
