下面给个用1stOpt解变系数微分方程组的例子,非常方便。
微分方程组:
x1'=dx1/dt=a*x1+b*x2+c;
x2'=dx2/dt=-b*x1+a*x2/c;
其中,a=-0.1, b=-1,c为变系数,范围[1,3]
t变化范围=[0,10*pi],初值x1(0)=1, x2(0)=1
1stOpt代码:
LoopConstant c=[1:0.1:3];
Constant a=-.1,b=-1;
Variable t=[0,10*pi],x1=1,x2=1;
Plot x1[x],x2;
ODEFunction x1'=a*x1+b*x2+c;
x2'=-b*x1+a*x2/c;
结果:
常微分方程(初值问题):
1: x1' = dx1/dt = (-0.1)*x1+(-1)*x2+(1)
2: x2' = dx2/dt = 0 -(-1)*x1+(-0.1)*x2/(1)
算法: 龙格-库塔-费尔博格法(Runge-Kutta-Fehlberg Method)
步长值: 0.0628318530717959
步长数: 500
结果:
t x1(t) x2(t) x1'(t) x2'(t)
0 1 1 -0.1 0.9
31.415927 0.137945214439506 0.990526871076025 -0.00432139251997565 0.0388925273319032 |