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

32 visualizaciones (últimos 30 días)
Hagen Gersie
Hagen Gersie el 1 de Jun. de 2022
Comentada: Hagen Gersie el 2 de Jun. de 2022
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!

Respuesta aceptada

William Rose
William Rose el 1 de Jun. de 2022
@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 comentarios
William Rose
William Rose el 2 de Jun. de 2022
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 el 2 de Jun. de 2022
Thanks, I figured that out as well and adapted accordingly. It now runs smoothly.

Iniciar sesión para comentar.

Más respuestas (1)

Sam Chak
Sam Chak el 1 de Jun. de 2022
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 comentarios
Sam Chak
Sam Chak el 2 de Jun. de 2022
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by