|
dx/dt=f1(t,x,y,z) dy/dt=f2(t,x,y,z) dz/dt=f3(t,x,y,z)として3元連立常微分方程式を
ルンゲクッタ法で解き、その解曲線群を描画します。
RANDOMIZE
LET XS=-4
LET XE=4
LET YS=-4
LET YE=4
SET WINDOW XS,XE,YS,YE
DRAW GRID
LET N=100 !'分割数
LET H=(XE-XS)/N
FOR L=1 TO 15
LET XX=INT(RND*10)-5
LET YY=INT(RND*10)-5
LET ZZ=INT(RND*10)-5
FOR I=1 TO 2
LET X=XX !'初期値 X
LET Y=YY !'初期値 Y
LET Z=ZZ !'初期値 Z
LET T=0
FOR J=1 TO N
LET K1=F1(T,X,Y,Z)
LET L1=F2(T,X,Y,Z)
LET M1=F3(T,X,Y,Z)
LET K2=F1(T+H/2,X+H/2*K1,Y+H/2*L1,Z+H/2*M1)
LET L2=F2(T+H/2,X+H/2*K1,Y+H/2*L1,Z+H/2*M1)
LET M2=F3(T+H/2,X+H/2*K1,Y+H/2*L1,Z+H/2*M1)
LET K3=F1(T+H/2,X+H/2*K2,Y+H/2*L2,Z+H/2*M2)
LET L3=F2(T+H/2,X+H/2*K2,Y+H/2*L2,Z+H/2*M2)
LET M3=F3(T+H/2,X+H/2*K2,Y+H/2*L2,Z+H/2*M2)
LET K4=F1(T+H,X+H*K3,Y+H*L3,Z+H*M3)
LET L4=F2(T+H,X+H*K3,Y+H*L3,Z+H*M3)
LET M4=F3(T+H,X+H*K3,Y+H*L3,Z+H*M3)
LET T0=T+H
LET X0=X+H*(K1+2*K2+2*K3+K4)/6
LET Y0=Y+H*(L1+2*L2+2*L3+L4)/6
LET Z0=Z+H*(M1+2*M2+2*M3+M4)/6
SET LINE COLOR "RED"
PLOT LINES:T,X;T0,X0
SET LINE COLOR "BLUE"
PLOT LINES:T,Y;T0,Y0
SET LINE COLOR "GREEN"
PLOT LINES:T,Z;T0,Z0
LET X=X0
LET Y=Y0
LET Z=Z0
LET T=T0
NEXT J
LET H=-H
NEXT I
NEXT L
FUNCTION F1(T,X,Y,Z) !'dx/dt=f1(t,x,y,z)
LET F1=X+Y+Z
END FUNCTION
FUNCTION F2(T,X,Y,Z) !'dy/dt=f2(t,x,y,z)
LET F2=-4*X-3*Y-7*Z
END FUNCTION
FUNCTION F3(T,X,Y,Z) !'dz/dt=f3(t,x,y,z)
LET F3=2*X+Y+5*Z
END FUNCTION
END
----------------------------------------------------------------------------------------
ローレンツの方程式を3元連立常微分方程式としてルンゲクッタ法で解き
Lorenzアトラクタを3D描画します。
https://ja.wikipedia.org/wiki/ローレンツ方程式
LET XS=-40
LET XE=40
LET YS=-40
LET YE=40
LET ZTH=0 ! z軸のまわりの回転角
LET XTH=0 ! x軸のまわりの回転角初期値
LET YTH=0 ! y軸のまわりの回転角初期値
DIM M(4,4),POINT(4),ROTX(4,4),ROTY(4,4)
SET WINDOW XS,XE,YS,YE
MAT M=ROTATE(ZTH)
MAT ROTX=IDN ! x軸のまわりの回転
LET ROTX(2,2)=COS(XTH)
LET ROTX(2,3)=SIN(XTH)
LET ROTX(3,2)=-SIN(XTH)
LET ROTX(3,3)=COS(XTH)
MAT ROTY=IDN ! y軸のまわりの回転
LET ROTY(1,1)=COS(YTH)
LET ROTY(1,3)=-SIN(YTH)
LET ROTY(3,1)=SIN(YTH)
LET ROTY(3,3)=COS(YTH)
MAT M=M*ROTX*ROTY
LET N=4000
LET H=1/128
LET A=10
LET B=28
LET C=8/3
LET X=1 !'初期値 X
LET Y=1 !'初期値 Y
LET Z=1 !'初期値 Z
LET T=0
FOR J=1 TO N
LET K1=F1(T,X,Y,Z)
LET L1=F2(T,X,Y,Z)
LET M1=F3(T,X,Y,Z)
LET K2=F1(T+H/2,X+H/2*K1,Y+H/2*L1,Z+H/2*M1)
LET L2=F2(T+H/2,X+H/2*K1,Y+H/2*L1,Z+H/2*M1)
LET M2=F3(T+H/2,X+H/2*K1,Y+H/2*L1,Z+H/2*M1)
LET K3=F1(T+H/2,X+H/2*K2,Y+H/2*L2,Z+H/2*M2)
LET L3=F2(T+H/2,X+H/2*K2,Y+H/2*L2,Z+H/2*M2)
LET M3=F3(T+H/2,X+H/2*K2,Y+H/2*L2,Z+H/2*M2)
LET K4=F1(T+H,X+H*K3,Y+H*L3,Z+H*M3)
LET L4=F2(T+H,X+H*K3,Y+H*L3,Z+H*M3)
LET M4=F3(T+H,X+H*K3,Y+H*L3,Z+H*M3)
LET T=T+H
LET X=X+H*(K1+2*K2+2*K3+K4)/6
LET Y=Y+H*(L1+2*L2+2*L3+L4)/6
LET Z=Z+H*(M1+2*M2+2*M3+M4)/6
CALL PLOT(X,Y,Z)
NEXT J
SUB PLOT(X,Y,Z)
LET POINT(1)=X
LET POINT(2)=Y
LET POINT(3)=Z
MAT POINT=POINT*M
PLOT LINES:POINT(1),POINT(2);
END SUB
FUNCTION F1(T,X,Y,Z) !'dx/dt=f1(t,x,y,z)
LET F1=A*(Y-X)
END FUNCTION
FUNCTION F2(T,X,Y,Z) !'dy/dt=f2(t,x,y,z)
LET F2=X*(B-Z)-Y
END FUNCTION
FUNCTION F3(T,X,Y,Z) !'dz/dt=f3(t,x,y,z)
LET F3=X*Y-C*Z
END FUNCTION
END
|
|