Вы находитесь на странице: 1из 2

Script de Euler e Ruth-Kutta

>> t=1;h=0.2;u10e=0;u20e=-1;u10r=0;u20r=-1;resp=[t u10e u20e u10r u20r]

resp =

1 0 -1 0 -1

>> u1e=u10e+h*u20e;u2e=u20e+h*(t-(u10e)^2);k11=h*u20r;k12=h*(t-
(u10r)^2);k21=h*(u20r+k12);k22=h*(t+h-(u10r+k11)^2);u1r=u10r+(k11+k21)/2;u2r=u20r+
(k12+k22)/2;t=t+h;u10e=u1e;u20e=u2e;u10r=u1r;u20r=u2r;resp=[resp;t u1e u2e u1r u2r]

resp =

1.0000 0 -1.0000 0 -1.0000


1.2000 -0.2000 -0.8000 -0.1800 -0.7840

>> u1e=u10e+h*u20e;u2e=u20e+h*(t-(u10e)^2);k11=h*u20r;k12=h*(t-
(u10r)^2);k21=h*(u20r+k12);k22=h*(t+h-(u10r+k11)^2);u1r=u10r+(k11+k21)/2;u2r=u20r+
(k12+k22)/2;t=t+h;u10e=u1e;u20e=u2e;u10r=u1r;u20r=u2r;resp=[resp;t u1e u2e u1r u2r]

resp =

1.0000 0 -1.0000 0 -1.0000


1.2000 -0.2000 -0.8000 -0.1800 -0.7840
1.4000 -0.3600 -0.5680 -0.3134 -0.5386

>> u1e=u10e+h*u20e;u2e=u20e+h*(t-(u10e)^2);k11=h*u20r;k12=h*(t-
(u10r)^2);k21=h*(u20r+k12);k22=h*(t+h-(u10r+k11)^2);u1r=u10r+(k11+k21)/2;u2r=u20r+
(k12+k22)/2;t=t+h;u10e=u1e;u20e=u2e;u10r=u1r;u20r=u2r;resp=[resp;t u1e u2e u1r u2r]

resp =

1.0000 0 -1.0000 0 -1.0000


1.2000 -0.2000 -0.8000 -0.1800 -0.7840
1.4000 -0.3600 -0.5680 -0.3134 -0.5386
1.6000 -0.4736 -0.3139 -0.3951 -0.2661

>> u1e=u10e+h*u20e;u2e=u20e+h*(t-(u10e)^2);k11=h*u20r;k12=h*(t-
(u10r)^2);k21=h*(u20r+k12);k22=h*(t+h-(u10r+k11)^2);u1r=u10r+(k11+k21)/2;u2r=u20r+
(k12+k22)/2;t=t+h;u10e=u1e;u20e=u2e;u10r=u1r;u20r=u2r;resp=[resp;t u1e u2e u1r u2r]

resp =

1.0000 0 -1.0000 0 -1.0000


1.2000 -0.2000 -0.8000 -0.1800 -0.7840
1.4000 -0.3600 -0.5680 -0.3134 -0.5386
1.6000 -0.4736 -0.3139 -0.3951 -0.2661
1.8000 -0.5364 -0.0388 -0.4195 0.0381

>> u1e=u10e+h*u20e;u2e=u20e+h*(t-(u10e)^2);k11=h*u20r;k12=h*(t-
(u10r)^2);k21=h*(u20r+k12);k22=h*(t+h-(u10r+k11)^2);u1r=u10r+(k11+k21)/2;u2r=u20r+
(k12+k22)/2;t=t+h;u10e=u1e;u20e=u2e;u10r=u1r;u20r=u2r;resp=[resp;t u1e u2e u1r u2r]

resp =
1.0000 0 -1.0000 0 -1.0000
1.2000 -0.2000 -0.8000 -0.1800 -0.7840
1.4000 -0.3600 -0.5680 -0.3134 -0.5386
1.6000 -0.4736 -0.3139 -0.3951 -0.2661
1.8000 -0.5364 -0.0388 -0.4195 0.0381
2.0000 -0.5441 0.2637 -0.3794 0.3836

>>
plot(resp(:,1),resp(:,2),'m-',resp(:,1),resp(:,3),'g-',resp(:,1),resp(:,4),'b-',res
p(:,1),resp(:,5),'r-'),grid
>>

Вам также может понравиться