plotting predator-prey model and its phase portrait

I have derived the eignevalues and eigenvectors of the predator prey model using symbolic notation. However, I am unable to plot the givn solution in the form it is given. Is it necessary to provide with values for the chosen variables in order to plot them?
syms A B D G t positive
syms x y x0 y0
assumeAlso([x0 y0], 'positive')
%The matrix dX/dt = f(X) is represented by F
F = [A*x - B*x*y; -G*y + D*x*y]
%The matrix v is used to denote the variables in focus
v = [x y]
%Now we find the Jacobian of F to approximate the given system about
% its stationary points. Through hand calculation, we know that the
% stationary points of the given system are: (0,0) and (G/D, A/B)
% This is represented by J1 and J2.
P1 = [0 0];
P2 = [G/D A/B];
j = jacobian(F, v)
J1 = subs(j,v,P1)
J2 = subs(j,v,P2)
%Now, we compute the eigenvalues and eigenvectors about the given points to
%determine the stability of the system. We know that, for a system to be
%stable, the eigenvalues of the system all have real part < 0
[T1, D1] = eig(J1)
[T2, D2] = eig(J2);
%T1 and T2 are eigenvectors while D1 and D2 are eigenvalues.
%In order to compute the phase portrait, we utilize x(t) = T*e^(Dt)*T^(-1)*x(0).
%For each case of stationary point, we get a different transformation
%matrix (i.e. A) and thus we find different x(t) for each case.
D1(t) = D1*t
D2(t) = D2*t
T1inv = inv(T1)
T2inv = inv(T2)
eD1(t) = exp(D1)
eD2(t) = exp(D2)
c1(t) = T1*eD1(t)*T1inv;
c2(t) = T2*eD2(t)*T2inv;
xt1(t) = c1(t)*[x0; y0]
xt2(t) = c2(t)*[x0; y0]
Can I plot it in terms of A,B,D and G?
Thanks

 Respuesta aceptada

If you want to plot the phase portrait, you can try using the numerical approach.
% Parameters
A = 2/3;
B = 4/3;
G = 1;
D = 1;
% Lotka–Volterra equations
f = @(t, x) [A*x(1) - B*x(1)*x(2);
-G*x(2) + D*x(1)*x(2)];
% Plotting multiple phase portraits
for x0 = 0.9:0.1:1.8
tspan = [0 10];
initc = [x0 x0]; % initial condition
[t, x] = ode45(f, tspan, initc);
plot(x(:,1), x(:,2), 'linewidth', 1), hold on
end
grid on, xlabel('x'), ylabel('y'), hold off
See Example at:

3 comentarios

Thanks a lot. Is there any way I can get a slider for A,B,G and D so that I can see the variation in plot with respect to the change in these values?
Sam Chak
Sam Chak el 25 de Jul. de 2022
You are welcome, @Krtin Kala. You can learn to design slider using the App Designer.
If you find the MATLAB code for the predator-prey model is helpful, please consider accepting ✔ and voting 👍 the Answer. Thanks!
Thanks a lot @Sam Chak. one final query. I have been trying to use quiver on the phase portrait graph. How should I initialize u and v for quiver(u,v,x,y)?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 22 de Jul. de 2022

Comentada:

el 25 de Jul. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by