How can I plot a three-species Lotka-Volterra model?

53 ビュー (過去 30 日間)
Hagen Gersie
Hagen Gersie 2022 年 6 月 1 日
コメント済み: Hagen Gersie 2022 年 6 月 2 日
Hi everyone!
I am a student of cultural studies and thus really out of my depth with MatLab. I have a seminar on Modeling Systems using linear and non-linear differential equations. I am now doing my exam project but I am quite confused by MatLab (this program is completely new to me).
I am trying to model a Lotka-Volterra system with three "species". I have already found my interaction parameters (using the least squares method). The equations now look like this:
dx(t)/dt = x(t)*(a0+a1*x(t)+a2*y(t)+a3*z(t))
dy(t)/dt = y(t)*(b0+b1*x(t)+b2*y(t)+b3*z(t))
dz(t)/dt = z(t)*(c0+c1*x(t)+c2*y(t)+c3*z(t))
a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3 are the parameters and constants. I have the values for them. I have tried to figure out how to write this function as a MatLab function but I have failed so far (and thus I cannot plot this system).
I tried naming x, y and z as the first three values of a vector (v), so that I have a function that looks a little like this:
function LV=lotka (t,v)
LV(1)=v(1)*(.......);
LV(2)=v(2)*(....);
LV(3)=v(3)*(.....);
end
I also used "ode45" (where I specified the time interval t) and the "figure" command to try to plot this but something along the way failed. Any help with writing this function would be appreciated.
I hope I made the problem clear. If needed I can provide the full code I have tried so far. However, as it is obviously wrong, I don't think it will help here.
Thank you!

採用された回答

William Rose
William Rose 2022 年 6 月 1 日
@Hagen Gersie, The answer from @Sam Chak is excellent . It has the virtues of conciseness and clarity.
You may be wondering why your way did not work. It is clear that you made a solid attempt. Your function lotka.m is actually a very good start. You got farther than a lot of people would. Please share your a,b,c,d constants, and the rest of your code, if you want to see how close you did or did not come to succeeding.
  6 件のコメント
William Rose
William Rose 2022 年 6 月 2 日
Your script stopped at 3.9 seconds because the equations were blowing up, and the integration routine, ode45() could not complete another time step. This is a result of the particular values for the constants a0..a3, b0..b3, c0..c3, and the initial condition.
Hagen Gersie
Hagen Gersie 2022 年 6 月 2 日
Thanks, I figured that out as well and adapted accordingly. It now runs smoothly.

サインインしてコメントする。

その他の回答 (1 件)

Sam Chak
Sam Chak 2022 年 6 月 1 日
Read doc ode45.
You can also follow the example and do something like this:
sigma = 10;
beta = 8/3;
rho = 28;
% Ordinary differential equations of the Lorenz system
f = @(t, x) [-sigma*x(1) + sigma*x(2); ...
rho*x(1) - x(2) - x(1)*x(3); ...
-beta*x(3) + x(1)*x(2)];
tspan = [0 100];
init = [1 1 1]; % initial condition
% Runge-Kutta Dormand-Prince 4/5 solver
[t, x] = ode45(f, tspan, init);
plot3(x(:,1), x(:,2), x(:,3)) % plot lines in 3D space
view(30, 30) % adjust view angles (in deg)
  3 件のコメント
Sam Chak
Sam Chak 2022 年 6 月 2 日
You are welcome, @Hagen Gersie. Please vote 👍 if you like the support, but consider accepting@William Rose's Answer for his kind effort in correcting and writing the MATLAB code for you. Have a nice day.
William Rose
William Rose 2022 年 6 月 2 日

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by