> restart: with(DEtools):
> dgl := diff(y(x),x) = 1+(y(x)-x)^2;
anfbed := y(0)=0.5;
:=
dgl ∂ =
∂
xy x( ) 1+(y x( )−x)2 :=
anfbed y 0( )=.5
> DEplot(dgl,y(x),x=0..1.9,y=0..7.5,[[anfbed]],linecolor=[blue], color=red,arrows=slim,axes=framed,thickness=2);
0 2 4 6
y(x)
0 0.5 x1 1.5
> dsolve({dgl,anfbed},y(x));
= ( )
y x x2− −1 2 x
− x 2
> f:=x+1/(2-x);
:=
f x+ 1
−
2 x
>
with(plots);
Warning, the name changecoords has been redefined
> dsolve({dgl,anfbed},y(x),type=numeric,method=classical[foreuler],’
stepsize’=1/10,output=listprocedure):
odeplot(%,[x,f-y(x)],0..1.8,numpoints=10,color=red,title=‘euler‘);
dsolve({dgl,anfbed},y(x),type=numeric,method=classical[heunform],’
stepsize’=1/10,output=listprocedure):
odeplot(%,[x,f-y(x)],0..1.8,numpoints=10,color=red,title=‘heunform
‘);
dsolve({dgl,anfbed},y(x),type=numeric,method=classical[rk4],’steps ize’=1/10,output=listprocedure):
odeplot(%,[x,f-y(x)],0..1.8,numpoints=10,color=red,title=‘rk4‘);
euler
0 0.5 1 1.5
2
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
heunform
0 0.05 0.1 0.15
0.2 0.25 0.3
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
rk4
0 0.0005
0.001 0.0015
0.002
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
dsolve({dgl,anfbed},y(x),type=numeric,method=classical[rk4],’steps ize’=1/100,output=listprocedure):
odeplot(%,[x,f-y(x)],0..1.8,numpoints=100,color=red,title=‘rk4‘);
euler
0 0.1 0.2 0.3 0.4
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
heunform
0 0.001 0.002 0.003 0.004
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
rk4
0 5e–08 1e–07 1.5e–07 2e–07 2.5e–07 3e–07
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
>
> dsolve({dgl,anfbed},y(x),type=numeric,method=classical[foreuler],’
stepsize’=1/1000,output=listprocedure):
dsolve({dgl,anfbed},y(x),type=numeric,method=classical[rk4],’steps ize’=1/1000,output=listprocedure):
odeplot(%,[x,f-y(x)],0..1.8,numpoints=1000,color=red,title=‘rk4‘);
euler
0 0.01 0.02 0.03 0.04 0.05
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
heunform
0 1e–05 2e–05 3e–05 4e–05
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
rk4
–1e–09 –5e–10 0 5e–10 1e–09
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
>