Function 在Scilab函数中求解模型时,如何查看/提取模型流演化?

Function 在Scilab函数中求解模型时,如何查看/提取模型流演化?,function,modeling,ode,scilab,Function,Modeling,Ode,Scilab,我编写了Lotka-Voterra模型(食饵-捕食者)作为Scilab函数,并用ODE解决了它。我的问题是我想看到流程的演变。我通过在解析中包含流找到了一个解决方案(在下面的脚本中只包含一个),但它确实“很重”。谁有更好的解决方案 //parameters x=[0.04,0.005,0.3,0.2] n = x(1);//birth rate of prey c = x(2);//capture rate e = x(3);//energy from capture m = x(4);//de

我编写了Lotka-Voterra模型(食饵-捕食者)作为Scilab函数,并用ODE解决了它。我的问题是我想看到流程的演变。我通过在解析中包含流找到了一个解决方案(在下面的脚本中只包含一个),但它确实“很重”。谁有更好的解决方案

//parameters
x=[0.04,0.005,0.3,0.2]
n = x(1);//birth rate of prey
c = x(2);//capture rate
e = x(3);//energy from capture
m = x(4);//death rate or predator

Tmax=100; // maximum time of simulation 
dt=0.01; // step of time 
t=0:dt:Tmax; //simulation time definition 
Ci = [20,30,0]'; //initial conditions (including for 1 flow)

//Lotka Volterra model
function [dy]=LV(t, y, n, c, e, m)
    GrowthP = n * y(1)
    IngestC = c * y(1) * y(2)
    MortC = m * y(2)
    dy(1) = GrowthP - IngestC
    dy(2) = IngestC * e - MortC
    dy(3) = IngestC //here one flow in ode
endfunction 

//resolution
sol=ode(Ci,0,t,LV)

//dataframe creation to stock data
soldef=zeros(3,10001);

//for the line 3 and form 2 to the last data it take the value, 
//remove the one of the previous time step and store it in soldef
for i = 2:length(sol(3,:))
    soldef(3,i)=sol(3,i)-sol(3,i-1);
end

//complete the dataframe with the stock
soldef(1:2,:)=sol(1:2,:)

感谢您对我的问题的兴趣和时间(对不起我的英语)

如果您想要动画显示结果,您可以使用下面的代码在图形上绘制越来越多的数据:

[row,col]=size(soldef);
scf(0);
clf(0);
plot2d(soldef(:,1:2)',rect=[0,0,col,max(soldef)]);  //plot first 2 points
en=gce();   //handle of the graphic entities
for i=3:col   //plot more and more points
  en.children(1).data=[1:i;soldef(3,1:i)]';   //update data matrices
  en.children(2).data=[1:i;soldef(2,1:i)]';
  en.children(3).data=[1:i;soldef(1,1:i)]';
  //you can save the frames here...
  xpause(1e4);    //wait some time if amination is too fast
end
如果您保存所有图形(例如使用
xs2gif()
),使用外部应用程序(google for“gif maker”),您甚至可以将结果制作一个.gif动画嵌入到网页或演示文稿中