Create a vector field

조회 수: 57 (최근 30일)
Alvaro Mª Zumalacarregui Delgado
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
David Goodmanson 2021년 3월 2일
편집: 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
David Goodmanson
David Goodmanson 2021년 3월 2일
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
thanks a lot for you help!!

댓글을 달려면 로그인하십시오.

추가 답변 (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