2015-01-14 2 views
1

Я написал модель Lotka Voterra (prey-predator) как функцию 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()), с внешним приложением (Google для «GIF-мейкера»), вы можете даже сделать GIF-анимацию из ваших результатов, возможность размещения в веб-страницу или презентацию.