Example
Consider the initial value problem
.
Since
,
satisfies a Lipschitz Condition in
with Lipschitz constant
.
Also, here, the solution is given by
, and thus
> ddy1:=diff(1+exp(-t),t,t);
which over
has a maximum at
:
, with
.
Using
, we find for the error bound:
.
In practice:
> f:=(t,y)->-y+t+1;
> w[0]:=1;h:=0.1;t[0]:=0;
> for i from 0 to 9 do t[i+1]:=t[i]+h: w[i+1]:=w[i]+h*f(t[i],w[i]):err.i:=abs(t[i+1]+exp(-t[i+1])-w[i+1]): errb.i:=0.05*(exp(t[i+1])-1): print(t[i+1],err.i,errb.i); od:
The error bound is a considerable overestimate of the real error in this case. We can decrease the step size, since the error bound is proportional to
:
> h:=0.01;for i from 0 to 99 do t[i+1]:=t[i]+h: w[i+1]:=w[i]+h*f(t[i],w[i]):err.i:=abs(t[i+1]+exp(-t[i+1])-w[i+1]): errb.i:=0.005*(exp(t[i+1])-1): od:
> for i from 9 by 10 to 99 do print(t[i+1],err.i,errb.i) od:
>