Create a vector field

16 visualizaciones (últimos 30 días)
Alvaro Mª Zumalacarregui Delgado
Alvaro Mª Zumalacarregui Delgado el 2 de Mzo. de 2021
I am trying to create a vector field of a equation system, but I think that I have the slope wrong:
this is the system:
dx/dt = P-ay
dy/d t= Q-bx
And this my code:
x1=0;
x2=5;
y1=0;
y2=5;
N = 20;
x = linspace(x1,x2,N);
y = linspace(y1,y2,N);
[X,Y]= meshgrid(x,y);
U = -P+a.*y;
V = -Q+b.*x;
[U,V]=meshgrid(U,V);
quiver (app.Axes2,X,Y,U,V);
This is the field I have get it, which from my point of view it doesn't have too many sense:

Respuesta aceptada

David Goodmanson
David Goodmanson el 2 de Mzo. de 2021
Editada: David Goodmanson el 2 de Mzo. de 2021
Hi ALvaro,
The code below sets P=Q=0 to make the spacial dependence more clear.
Rather than meshgridding the 1d velocity vectors U1 and V1 to make U2 and V2 (I renamed them), you should define them directly as functions of the meshgridded matrix coordinates X and Y. Figure 2 satisfies the original equations and is much different than the original result of Figure(1).
There is also a question of overall sign reversal in the approach you used, but sign reversing back does not solve the problem. The real issue is not the sign but the method for calculating U and V.
a = .1;
b = .2;
P = 0;
Q = 0;
x1=-5;
x2=5;
y1=-5;
y2=5;
N = 20;
x = linspace(x1,x2,N);
y = linspace(y1,y2,N);
[X,Y]= meshgrid(x,y);
U1 = -P +a.*y; % sign reversed?
V1 = -Q +b.*x; % sign reversed?
[U2,V2]=meshgrid(U1,V1);
figure(1)
quiver (X,Y,U2,V2);
U3 = P -a.*Y;
V3 = Q -b.*X;
figure(2)
quiver (X,Y,U3,V3);
  3 comentarios
David Goodmanson
David Goodmanson el 2 de Mzo. de 2021
In this case there is an analytic solution, but in the general case you would define the differential equations in a function, and then hand it an ode solver such as ode45. You can define the function yourself (see examples in documentation for odes) or use the odeToVectorField function to assist.
Alvaro Mª Zumalacarregui Delgado
Alvaro Mª Zumalacarregui Delgado el 2 de Mzo. de 2021
thanks a lot for you help!!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by