Borrar filtros
Borrar filtros

How to plot nullclines with differential equations

48 visualizaciones (últimos 30 días)
Zachary David
Zachary David el 4 de Oct. de 2021
Respondida: Star Strider el 4 de Oct. de 2021
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!

Respuesta aceptada

Star Strider
Star Strider el 4 de Oct. de 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
nullX1 = 24×24
-2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.6000 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -2.2700 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.9400 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.6100 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -1.2800 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.9500 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.6200 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 -0.2900 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700 0.3700
nullX2= g - d.*x1
nullX2 = 24×24
3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600 3.9000 3.4800 3.0600 2.6400 2.2200 1.8000 1.3800 0.9600 0.5400 0.1200 -0.3000 -0.7200 -1.1400 -1.5600 -1.9800 -2.4000 -2.8200 -3.2400 -3.6600 -4.0800 -4.5000 -4.9200 -5.3400 -5.7600
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.
.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by