SCILAB ODE 在求解 Lotka-Volterra 系统时显示问题

问题描述

我正在用代码求解简单的 ODE 方程:

u=6;
z=2;
t=0:1:2000;
v0=0.04+0.001*u;
p0=0.03+0.001*z;
y0=[p0;v0];
t0=0;
b=0.2-0.01*u;
d=0.1;
c=0.4;
a=0.5;

 
function dx=f(t,x)
 dx(1)=b*x(1)-d*x(1)*x(2);
 dx(2)=c*x(2)-a*x(1)*x(2);
 x=[x(1);x(2)];
endfunction
y=ode(y0,t0,t,f);

问题是,使用这样的 t 会显示错误

intdy--  t (=r1) illegal      
      where r1 is :   0.9560000000000D+03                                        
      t is not in [tcur-hu,tcur] = [r1,r2]
      where r1 is :   0.9553617168733D+03   and r2 :   0.9555070182087D+03       
intdy--  t (=r1) illegal      
      where r1 is :   0.9570000000000D+03                                        
      t is not in [tcur-hu,r2]
      where r1 is :   0.9553617168733D+03   and r2 :   0.9555070182087D+03       
lsoda--  problems due to intdy. itask=i1,tout=r1
      where i1 is :          1                                                   
      where r1 is :   0.9570000000000D+03                                        
Illegal input detected (see printed message).

ode: lsoda exit with state -3.

我知道问题从 t=956 开始,但我不明白我该如何解决它。是否与变量的值有关?

解决方法

您对第二个方程的符号有误(我想您正在尝试求解 Lotka-Volterra 猎物-捕食者系统)。正确的右边是

function dx=f(t,x)
 dx(1) =  b*x(1)-d*x(1)*x(2);
 dx(2) = -c*x(2)+a*x(1)*x(2);
endfunction

更好的时间离散化,例如

t=0:0.1:200;

你会得到以下结果: enter image description here