フィルターのクリア

Quiver with a system of ODEs.

22 ビュー (過去 30 日間)
Johan Bergman
Johan Bergman 2019 年 12 月 6 日
コメント済み: darova 2019 年 12 月 9 日
Hello everyone.
I am trying to plot the solutions to a system of ODEs to see how it matches to the field that quiver would plot.
The system:
x' = cos(x-y) , x(0) = x0
y' = sin(x*y) , y(0) = y0
Unsure whether I managed to translate the system into Matlab, but here is the code:
f = @(x,y) [cos(y(1)-y(2)) sin(y(1).*y(2))]
The rest of the script:
x = linspace(0,3);
y = linspace(0,3);
grid on
[X,Y] = meshgrid(x,y);
u = ???; v = ???;
quiver(X, Y, u, v, 0.9)
hold on
y0 = 1;
x0 = 2;
[T,Y] = ode45(f,[0 3],[x0; y0]);
plot(T,Y)
I don't understand how you're suppposed to use quiver. I don't quite understand what the help documentation is saying about "u" and "v". I want to see how the solutions follow the vector field produced by quiver but have no idea how to define u or v. The inital conditions y0 and x0 can be varied to see how the solutions would follow the vector field. Thanks a lot!
  8 件のコメント
Adam Danz
Adam Danz 2019 年 12 月 9 日
@darova , perhaps your comment could be copied to the answers section so Johan Bergman can accept it.
darova
darova 2019 年 12 月 9 日
I agree, Adam. Thanks bro
ANd9GcTHS0D629oBsQ9CYzDO9y0r6FCmEEPVUJeyHlPB9C24bWmZr3A38A&s

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

回答 (1 件)

darova
darova 2019 年 12 月 9 日
For vector field
u = x'; v = y';
To plot the curve
[T,Y] = ode45 ...
plot(Y(:,1),Y(:,2)) % (x,y)
I suppose x and y depends on t (time). As you assumed above
% f = @(x,y) [cos(y(1)-y(2)) sin(y(1).*y(2))]
f = @(t,u) [cos(u(1)-u(2)) sin(u(1).*u(2))]
[T,U] = ode45 ...
% u(1) == U(:,1) == x
% u(2) == U(:,2) == y

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by