微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。