- IC() is the vector of initial conditions. Therefore the values of [p1, p2, p3] at the initial time (t=0) are the values given in IC. Those were defined at the top to be IC=[h0, i0, v0].
- RHS() is a function that returns a 3-element vector whose values are the time derivatives [dp1/dt, dp2/dt, dp3/dt].
- t=[0,365] is the time range for integraiton.
Predator/Prey Model questions
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Nicholas Carr
am 28 Mär. 2021
Kommentiert: Nicholas Carr
am 30 Mär. 2021
I'm trying to create a predator prey model with three different populations.
I was able to construct this using my notes/online tutorials, but I do not understand what all of this does (nor if I did this correctly). In my notes/ online tutorials, it seems p(1) would be the first population. I don't see where this is set up though and how it is updated. If anyone could explain how the computer reads these lines of , I'd greatly appreciate it.
function population
%initial conditions
h0=100; i0=1; v0=1;
IC=[h0,i0,v0];
t = [0 365];
B=0.07;
Ri=0.01;
Rv=0.01;
Di=0.03;
Dv=1;
Bv=0.03;
Rr=0.001;
[t,p]= ode15s(@RHS, t,IC );
figure(1)
plot(t ,p(:,1),'linewidth',2,'color','b')
hold on
plot(t ,p(:,2),'linewidth',2,'color','g')
hold on
plot(t ,p(:,3),'linewidth',2,'color','r')
grid on;
xlabel('time', 'FontSize', 20);
ylabel('Population', 'FontSize', 20);
function dpdt= RHS(t,p)
dpdt_1=(B*p(1)) - (Rv*p(1)*p(3)) - (Ri*p(1)*p(2)) + (Rr*p(2));
dpdt_2=(Ri*p(1)*p(2)) - (Di*p(2)) - (Rr*p(2));
dpdt_3=(Bv*(p(1)+p(2))*p(3))- (Dv*p(3));
dpdt=[dpdt_1;dpdt_2;dpdt_3];
end
end
0 Kommentare
Akzeptierte Antwort
William Rose
am 28 Mär. 2021
@Nicholas Carr, line
[t,p]= ode15s(@RHS, t,IC );
is where the action is in this script.
Outputs: p() is Nx3array with populations p1, p2, p3, at the N times given in the Nx1 vector t().
Inputs:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!