# Create a vector field

37 ビュー (過去 30 日間)
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:

サインインしてコメントする。

### 採用された回答

David Goodmanson 2021 年 3 月 2 日

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 件のコメント表示非表示 2 件の古いコメント
Alvaro Mª Zumalacarregui Delgado 2021 年 3 月 2 日
thanks a lot for you help!!

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by