How do I show a quiver plot from a matrix?

11 ビュー (過去 30 日間)
Dylan Voss
Dylan Voss 2020 年 7 月 14 日
編集済み: Cris LaPierre 2020 年 7 月 20 日
I am trying to graph this direction field:
x' = (1 1; 4 1)x
This is my code:
a = [1 1;4 1];
x = [x y];
[x,y] = meshgrid(-10:1:10,-10:1:10);
dx = 1;
dy = a.*x.*1;
r = ( dx.^2 + dy.^2 ).^0.5;
u = dx./r;
v = dy./r;
figure
quiver(x,y,u,v);
It returns this error:
ꕋerror: QuiverPlot: product: nonconformant arguments (op1 is 2x2, op2 is 21x21)
error: called from
QuiverPlot at line 5 column 4
I guess my x vector does not have the same dimension as my a vector, even though a has two columns and x has two rows.
As a side note, this problem was given by Boyce and Diprima's textbook with no context regarding the code.
  1 件のコメント
Dylan Voss
Dylan Voss 2020 年 7 月 14 日
編集済み: Cris LaPierre 2020 年 7 月 14 日
I edited my code, putting a semicolon in matrix t (formerly matrix x):
a = [1 1;4 1];
[x,y] = meshgrid(-10:1:10,-10:1:10);
t = [x;y];
dx = 1;
dy = a.*t.*1;
r = ( dx.^2 + dy.^2 ).^0.5;
u = dx./r;
v = dy./r;
figure
quiver(x,y,u,v);
Matrix x is still a 42 by 21 matrix evidently.......??

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

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 7 月 14 日
The issue is with your calculation of dy. Variable a is 2x2, but t is 42x21.
  2 件のコメント
Dylan Voss
Dylan Voss 2020 年 7 月 19 日
Why is t 42 by 21?
Cris LaPierre
Cris LaPierre 2020 年 7 月 20 日
編集済み: Cris LaPierre 2020 年 7 月 20 日
Because you create it using x and y, specifically placing y directly underneath x, and they are each 21x21. Perhaps take a look at the documentation for meshgrid.

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by