2015-01-14 49 views
1

我將Lotka Voterra模型(捕食捕食者)寫成Scilab函數,並用ODE解決它。我的問題是我想看到流量的演變。我通過在決議中包含流程(在下面的腳本中僅包含一個)而找到了解決方案,但它確實很「重」。任何人有更好的解決方案?在Scilab函數中求解模型時如何查看/提取模型流進化?

//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,:) 

謝謝你的興趣,如果你想你的結果的動畫顯示你給我的問題(和我的英語很抱歉)

回答

0

的時候,你可以用下面的代碼繪製越來越多在圖表上的數據:

[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()),與外部應用程序(谷歌的「GIF製造者」),你甚至可以讓你的結果,使嵌入在一個.gif動畫一個網頁或演示文稿。