Gość |
Wysłany: Pią 11:41, 26 Maj 2006 Temat postu: RungeKutta4 |
|
function df=funkcja(t,y)
df=t+y;
endfunction
function Runge_KuttaIV=Runge_KuttaIV(y0,t,n,h)
Runge_KuttaIV(1)=y0;
for i=2:n
k1=h*funkcja(t(i-1),Runge_KuttaIV(i-1));
k2=h*funkcja(t(i-1)+(1/2)*h,Runge_KuttaIV(i-1)+(1/2)*k1);
k3=h*funkcja(t(i-1)+(1/2)*h,Runge_KuttaIV(i-1)+(1/2)*k2);
k4=h*funkcja(t(i-1)+h,Runge_KuttaIV(i-1)+k3);
Runge_KuttaIV(i)=Runge_KuttaIV(i-1)+(1/6)*(k1+(2*k2)+(2*k3)+k4);
endfor
endfunction
function df=dot(y,t)
df=t+y;
endfunction
a=0;
b=0.5;
h=0.05;
t=a:h:b;
n=length(t);
y0=1;
Runge_KuttaIV=Runge_KuttaIV(y0,t,n,h);
lsode=lsode("dot",y0,t);
function y=rozwiazanie_scisle(t)
for i=1:length(t)
y(i)=2*exp(t(i))-t(i)-1;
endfor
endfunction
y=rozwiazanie_scisle(t);
%wykresy
gset grid;
hold on;
printf("Rozwiazanie scisle\n");
plot(y);
hold on;
pause;
printf("Biblioteka\n");
plot(lsode);
hold on;
pause;
printf("Runge Kutta IV\n");
plot(Runge_KuttaIV);
hold on;
pause; |
|