Harj. 2 LV

pe 28.9.01 HA

1.

> restart:

Warning, the name changecoords has been redefined

Picardin iteraatio:

> y[n](x):=y[0]+Int(f(t,y[n-1](t)),t=x[0]..x);

y[n](x) := y[0]+Int(f(t,y[n-1](t)),t = x[0] .. x)

a)

> restart: f:=(x,y)->x+y; y[0]:=0:

Warning, the name changecoords has been redefined

f := proc (x, y) options operator, arrow; x+y end p...

> y[1]:=y[0]+simplify(int(subs(x=t,f(t,y[0])),t=0..x));

y[1] := 1/2*x^2

> y[2]:=y[0]+simplify(int(subs(x=t,f(t,y[1])),t=0..x));
y[3]:=y[0]+simplify(int(subs(x=t,f(t,y[2])),t=0..x));
y[4]:=y[0]+simplify(int(subs(x=t,f(t,y[3])),t=0..x));

y[2] := 1/2*x^2+1/6*x^3

y[3] := 1/2*x^2+1/6*x^3+1/24*x^4

y[4] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5

> y[5]:=y[0]+simplify(int(subs(x=t,f(t,y[4])),t=0..x));
y[6]:=y[0]+simplify(int(subs(x=t,f(t,y[5])),t=0..x));
y[7]:=y[0]+simplify(int(subs(x=t,f(t,y[6])),t=0..x));
y[8]:=y[0]+simplify(int(subs(x=t,f(t,y[7])),t=0..x));
y[9]:=y[0]+simplify(int(subs(x=t,f(t,y[8])),t=0..x));

y[5] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

y[6] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

y[7] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

y[8] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

y[9] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

>
y[2]:=x^2/2+simplify(int(subs(x=t,y[1]),t=0..x));
y[3]:=x^2/2+simplify(int(subs(x=t,y[2]),t=0..x));
y[4]:=x^2/2+simplify(int(subs(x=t,y[3]),t=0..x));
y[5]:=x^2/2+simplify(int(subs(x=t,y[4]),t=0..x));
y[6]:=x^2/2+simplify(int(subs(x=t,y[5]),t=0..x));
y[7]:=x^2/2+simplify(int(subs(x=t,y[6]),t=0..x));

> ytarkka:=dsolve({diff(yy(x),x)=x+yy(x),yy(0)=0},yy(x));

y[2] := 1/2*x^2+1/6*x^3

y[3] := 1/2*x^2+1/6*x^3+1/24*x^4

y[4] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5

y[5] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

y[6] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

y[7] := 1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^...

ytarkka := yy(x) = -x-1+exp(x)

>

> Y:=rhs(ytarkka);

Y := -x-1+exp(x)

> series(Y,x=0,10);

series(1/2*x^2+1/6*x^3+1/24*x^4+1/120*x^5+1/720*x^6...

>

Aivan ilmeisesti tuottaa Taylorin sarjan, suppenee kaikkialla. (Kehitelmä voitaisiin todistaa induktiolla.)

b)

> restart: f:=(x,y)->x+y; y[0]:=-1:

Warning, the name changecoords has been redefined

f := proc (x, y) options operator, arrow; x+y end p...

>

> k:='k':for k to 10 do y[k]:=y[0]+simplify(int(subs(x=t,f(t,y[k-1])),t=0..x)); end do;
k;

>

y[1] := -1+1/2*x^2-x

y[2] := -1-x+1/6*x^3

y[3] := -1-x+1/24*x^4

y[4] := -1-x+1/120*x^5

y[5] := -1-x+1/720*x^6

y[6] := -1-x+1/5040*x^7

y[7] := -1-x+1/40320*x^8

y[8] := -1-x+1/362880*x^9

y[9] := -1-x+1/3628800*x^10

y[10] := -1-x+1/39916800*x^11

11

> ytarkka:=dsolve({diff(yy(x),x)=x+yy(x),yy(0)=-1},yy(x));

ytarkka := yy(x) = -x-1

> Y:=rhs(ytarkka);plot([Y,seq(y[k],k=0..10)],x=-3..3);

Y := -x-1

[Maple Plot]

> plot([Y,y[10]],x=-5..5);

[Maple Plot]

>

c)

> restart: f:=(x,y)->y^2; y[0]:=1:

Warning, the name changecoords has been redefined

f := proc (x, y) options operator, arrow; y^2 end p...

> for k to 4 do y[k]:=y[0]+simplify(int(subs(x=t,f(t,y[k-1])),t=0..x)); end do;
k;

y[1] := 1+x

y[2] := 1+1/3*x^3+x^2+x

y[3] := 1+1/63*x^7+1/9*x^6+1/3*x^5+2/3*x^4+x^3+x^2+...

y[4] := 1+1/59535*x^15+1/3969*x^14+1/567*x^13+1/126...

5

> y[2]:=series(y[2],x=0,4);y[3]:=series(y[3],x=0,8);y[4]:=series(y[4],x=0,16);

y[2] := series(1+1*x+1*x^2+1/3*x^3,x)

y[3] := series(1+1*x+1*x^2+1*x^3+2/3*x^4+1/3*x^5+1/...

y[4] := series(1+1*x+1*x^2+1*x^3+1*x^4+13/15*x^5+2/...

>

>

>

>

> ytarkka:=dsolve({diff(yy(x),x)=yy(x)^2,yy(0)=1},yy(x));
Y:=rhs(ytarkka);plot([Y,seq(y[k],k=0..4)],x=-1..1-0.1);
plot([Y,y[4]],x=-1..1-0.1);
plot(Y-y[4],x=-1..1-0.1);

ytarkka := yy(x) = -1/(x-1)

Y := -1/(x-1)

[Maple Plot]

[Maple Plot]

[Maple Plot]

> series(Y,x=0,7);

series(1+1*x+1*x^2+1*x^3+1*x^4+1*x^5+1*x^6+O(x^7),x...

>

d)

> restart: f:=(x,y)->3*y/x; y[0]:=1:

for k to 3 do y[k]:=y[0]+simplify(int(subs(x=t,f(t,y[k-1])),t=1..x)); end do;

Warning, the name changecoords has been redefined

f := proc (x, y) options operator, arrow; 3*y/x end...

y[1] := 1+3*ln(x)

y[2] := 1+3*ln(x)+9/2*ln(x)^2

y[3] := 1+3*ln(x)+9/2*ln(x)^2+9/2*ln(x)^3

> y[4]:=y[0]+simplify(int(subs(x=t,f(t,y[3])),t=1..x));

y[4] := 1+3*ln(x)+9/2*ln(x)^2+9/2*ln(x)^3+27/8*ln(x...

> y[5]:=y[0]+simplify(int(subs(x=t,f(t,y[4])),t=1..x));

y[5] := 1+3*ln(x)+9/2*ln(x)^2+9/2*ln(x)^3+27/8*ln(x...

> ytarkka:=dsolve({diff(yy(x),x)=3*yy(x)/x,yy(1)=1},yy(x)); Y:=rhs(ytarkka);

ytarkka := yy(x) = x^3

Y := x^3

> series(y[3],x=1,4);series(Y,x=1,4);

series(1+3*(x-1)+3*(x-1)^2+1*(x-1)^3+O((x-1)^4),x=-...

series(1+3*(x-1)+3*(x-1)^2+1*(x-1)^3,x=-(-1))

> series(y[4],x=1,4);series(Y,x=1,4);

series(1+3*(x-1)+3*(x-1)^2+1*(x-1)^3+O((x-1)^4),x=-...

series(1+3*(x-1)+3*(x-1)^2+1*(x-1)^3,x=-(-1))

> series(y[5],x=1,5);series(Y,x=1,4);

series(1+3*(x-1)+3*(x-1)^2+1*(x-1)^3+O((x-1)^5),x=-...

series(1+3*(x-1)+3*(x-1)^2+1*(x-1)^3,x=-(-1))

> plot([Y,seq(y[k],k=0..5)],x=0.2..2);plot([Y,y[4]],x=0.2..2);plot(Y-y[4],x=0.2..2);

[Maple Plot]

[Maple Plot]

[Maple Plot]

2.

3.

4.

5.

6. Stabiilisuustarkasteluja

> restart:with(DEtools): with(plots):

Warning, the name changecoords has been redefined

> read("/home/apiola/opetus/peruskurssi/v2-3/301/maple/v301.mpl"); # Vaihda kommentit.

PL := proc (xfun) options operator, arrow; picklind...

> # read("/p/edu/mat-1.414/maple/v301.mpl"); # Kurssihakemisto, näkyy luokissa.

> #op(Euler);op(RK4);op(BE);

> f:=(t,y)->-2*alpha*(t-1)*y;

f := proc (t, y) options operator, arrow; -2*alpha*...

> diff(f(t,y),y);

-2*alpha*(t-1)

Tämä on < 0, kun t > 1 ja päinvastoin. Asian näkyy diffyhtälön ratkaisukäyräparvessa niin, että käyrät menevät "nippuun" (tai "suppuun"), kun

aika kasvaa lähdettäessä arvon t=1 oikealta puolelta ja vasemmalta taas päinvastoin.

> dyht:=diff(y(t),t)=-2*alpha*(t-1)*y(t):

> dsolve(diff(y(t),t)=-2*alpha*(t-1)*y(t),y(t));

y(t) = _C1*exp(-alpha*t*(t-2))

> Y:=subs(_C1=C,rhs(%));

Y := C*exp(-alpha*t*(t-2))

> alpha:=2:plot([seq(Y,C=[0.1,.5,0.6,0.7,-0.1,-0.2,-0.7])],t=-1..3);

[Maple Plot]

No tässä tuo yllä mainittu niputuskäytös näkyy. Jos siis 1:n oikealta lähdetään epätarkalla alkuarvolla, niin yhtälön stabiilisuus on omiaan korjaamaan tilannetta. Toki asiat voivat silti mennä mäkeen, jos askelpituuden valinnassa ei oteta huomioon numeerisen menetelmän asettamaa stabiilisuusvaatimusta.

Piirretään ratkaisukäyrät vielä suuntakenttäpiirrokseen.

> display([DEplot(dyht,y(t),t=-1..3,y=-5..5,color=grey),plot([seq(Y,C=[0.1,.5,0.6,0.7,-0.1,-0.2,-0.7])],t=-1..3)]);

[Maple Plot]

No niin, tehtäväpaperissa oleva kaava antaa EM:n stabiilisuusehdon:

> h < 2/abs(diff('f(t,y)',y));

h < 2*1/abs(diff(f(t,y),y))

> dfy:=diff(f(t,y),y); # Muista: alpha:=2

dfy := -4*t+4

> seq(evalf(dfy),t=[1,2,3,4,4.5]);

0., -4., -8., -12., -14.0

Jos käytämme vaikka kesimmäistä arvoa -8, saamme:

> h < 2/8; m=3.5/0.25;

h < 1/4

m = 14.00000000

> Euler(f,1,4.5,1,14);

[1, 1], [1.250000000, 1.], [1.500000000, .750000000...
[1, 1], [1.250000000, 1.], [1.500000000, .750000000...

> plot([%]);

[Maple Plot]

> plot([Euler(f,1,4.5,1,7)]);h=3.5/7;

[Maple Plot]

h = .5000000000

> EM6:=plot([Euler(f,1,4.5,1,6)]): h=3.5/6;

h = .5833333333

> suuntak:=DEplot(dyht,y(t),t=1..4.5,y=-5..5,color=grey):

> display(EM6,suuntak);

[Maple Plot]

> BE6:=plot([BE(f,1,4.5,1,6,2)]): h=3.5/6;

h = .5833333333

> suuntak:=DEplot(dyht,y(t),t=1..4.5,y=-1..2,color=grey):

> display(BE6,suuntak);

[Maple Plot]

> BE3:=plot([BE(f,1,4.5,1,3,2)]): h=3.5/3;

h = 1.166666667

> display(BE3,suuntak);

[Maple Plot]

Tämä on vakuuttavaa, vaikuttavaa, dramaattista! BE ottaa vain 3 askelta ja etenee horjumatta kohti oikeaa ratkaisua. Itse asiassa BE on aina stabiili, jos yhtälö on stabiili, siinä stabiilisuus ei aseta mitään rajoitusta askelpituudelle.