How to plot nullclines with differential equations
48 views (last 30 days)
Show older comments
Im trying to plot nullclines on top of a mesh grid then use ode 45
i cant seem to get the nullclines on their though after googling for hours. This is my code:
x1min = -1; x1max = 6; x2min = -1; x2max = 6;
x1step = 0.3; x2step = 0.3;
[x1, x2] = meshgrid(x1min:x1step:x1max, x2min:x2step:x2max);
a = 1.5;
b=1.1;
g=2.5;
d=1.4;
dx1 = -a*x1+b*x1*x2;
dx2 = g*x2-d*x1*x2;
nullX1= -a + b.*x2;
nullX2= g - d.*x1;
quiver(x1, x2, dx1,dx2,'AutoScaleFactor',0.5)
axis([x1min x1max x2min x2max])
xlabel('$x1$','Interpreter','latex')
ylabel('$x2$','Interpreter','latex')
title('Vector field example','Interpreter','latex')
x=0:0.5:30;
plot(x,nullX1,'r-')
hold on
plot(x,nullX2,'k-')
hold on
*****It keeps telling my my vectors must be the same length, so not sure if im using the wrong parameters.
Thanks!
0 Comments
Accepted Answer
Star Strider
on 4 Oct 2021
Work-around —
x = linspace(0, 30, size(nullX1,1)); % Use 'linspace' To Create Correct Length 'x'
x1min = -1; x1max = 6; x2min = -1; x2max = 6;
x1step = 0.3; x2step = 0.3;
[x1, x2] = meshgrid(x1min:x1step:x1max, x2min:x2step:x2max);
a = 1.5;
b=1.1;
g=2.5;
d=1.4;
dx1 = -a*x1+b*x1*x2;
dx2 = g*x2-d*x1*x2;
nullX1= -a + b.*x2
nullX2= g - d.*x1
quiver(x1, x2, dx1,dx2,'AutoScaleFactor',0.5)
axis([x1min x1max x2min x2max])
xlabel('$x1$','Interpreter','latex')
ylabel('$x2$','Interpreter','latex')
title('Vector field example','Interpreter','latex')
% x=0:0.5:30;
x = linspace(0, 30, size(nullX1,1)); % Use 'linspace' To Create Correct Length 'x'
plot(x,nullX1,'r-')
hold on
plot(x,nullX2,'k-')
hold on
Experiment to get different results.
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!