How to add arrows to solution trajectories using ode?

16 次查看(过去 30 天)
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])

采纳的回答

Star Strider
Star Strider 2014-9-2
编辑:Star Strider 2014-9-2
Meet the quiver function.
The odephas2 output function is also worth a look, although I’ve never used it.
  2 个评论
Rose
Rose 2014-9-2
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 2014-9-2
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by