Azzera filtri
Azzera filtri

How to add arrows to solution trajectories using ode?

13 visualizzazioni (ultimi 30 giorni)
I have a system of two odes and i want to plot the phase portrait with arrows and clearly representing the stable and unstable steady states. The problem is that i am getting the solution trajectories but without arrows. So it is very difficult to see which steady state is stable. Here is the ode system:
function dy = twodim(~,y, mu, d1, d2, K, n, p, sigma1, sigma2)
dy(1,1) = mu.*((y(1) + y(2)).^n)./(K.^n + (y(1) + y(2)).^n) - d1.*y(1) - y(1).*(sigma1 - sigma2.*(y(2)./(y(1) + y(2) + 1e-12))) ;
dy(2,1) = y(1).*(sigma1 - sigma2.*(y(2)./(y(1) + y(2) + 1e-12))) - (p + d2).*y(2);
Below is the part of the code I use to draw the solution trajectories:
mu = 2000;
K = 27000;
d1 = 0;
d2 = 0;
sigma1 = 0.25;
sigma2 = 0.75;
p = 0.24;
n = 1;
close all; hold on
for a = 0:5250:15000
for b = 0:5250:15000
[t, y] = ode45(@(t,y)twodim(t,y, mu, d1, d2, K, n, p, sigma1, sigma2), 0:0.2:15000, [a; b]);
plot(y(:,1), y(:,2))
end
end
hold off
axis([0 15000 0 15000])

Risposta accettata

Star Strider
Star Strider il 2 Set 2014
Modificato: Star Strider il 2 Set 2014
Meet the quiver function.
The odephas2 output function is also worth a look, although I’ve never used it.
  2 Commenti
Rose
Rose il 2 Set 2014
i tried the quiver function but it doesn't draw arrows along with the solution trajectories only, it draws them on the whole grid.
Star Strider
Star Strider il 2 Set 2014
I’m not quite sure I understand the problem, or your ODE, so I don’t know if this is what you want. It is sometimes necessary to experiment with quiver:
arowscal = 10;
quiver(y(:,1), y(:,2), gradient(-y(:,1)), gradient(y(:,1)), arowscal )
The ‘arowscal’ parameter lengthens the arrows so you can see them.
I’m not aware of any other way to add arrows to plots, although there may be some File Exchange routines that will do it.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by