|
LET TS=0 !' TS~TEまで
LET TE=2
LET M=3 !'M元連立常微分方程式
DIM Y(M),Y1(M),Y2(M),Y3(M),K1(M),K2(M),K3(M),K4(M)
LET N=20 !'分割数
LET H=(TE-TS)/N
LET T=0
LET Y(1)=INT(RND*10)-5 !'初期値 x
LET Y(2)=INT(RND*10)-5 !'初期値 y
LET Y(3)=INT(RND*10)-5 !'初期値 z
FOR I=1 TO N
FOR J=1 TO M
LET K1(J)=F(J,T,Y)
NEXT J
FOR J=1 TO M
LET Y1(J)=Y(J)+H/2*K1(J)
NEXT J
FOR J=1 TO M
LET K2(J)=F(J,T+H/2,Y1)
NEXT J
FOR J=1 TO M
LET Y2(J)=Y(J)+H/2*K2(J)
NEXT J
FOR J=1 TO M
LET K3(J)=F(J,T+H/2,Y2)
NEXT J
FOR J=1 TO M
LET Y3(J)=Y(J)+H*K3(J)
NEXT J
FOR J=1 TO M
LET K4(J)=F(J,T+H,Y3)
NEXT J
LET T=T+H
FOR J=1 TO M
LET Y(J)=Y(J)+H*(K1(J)+2*K2(J)+2*K3(J)+K4(J))/6
NEXT J
PRINT T;
FOR J=1 TO M
PRINT Y(J);
NEXT J
PRINT
NEXT I
END
EXTERNAL FUNCTION F(NUM,T,Y()) !' x=Y(1) y=Y(2) z=Y(3) ...
SELECT CASE NUM
CASE 1
LET F=Y(1)+Y(2)+Y(3) !'dx/dt=f1(t,y(1),y(2),y(3))=x+y+z
CASE 2
LET F=-4*Y(1)-3*Y(2)-7*Y(3) !'dy/dt=f2(t,y(1),y(2),y(3))=-4*x-3*y-7*z
CASE 3
LET F=2*Y(1)+Y(2)+5*Y(3) !'dz/dt=f3(t,y(1),y(2),y(3))=2*x+y+5*z
END SELECT
END FUNCTION
|
|