フィルターのクリア

Gradient plot as arrow - strange result

3 ビュー (過去 30 日間)
Gennaro Arguzzi
Gennaro Arguzzi 2017 年 11 月 12 日
コメント済み: Jan 2017 年 11 月 12 日
I tried to plot gradient as an arrow with:
x=-10:2:10;
f = -x.^2;
u = gradient(x);
n=length(u);
for i=1:n
a(i)=0;
end
quiver(a,a,u,a)
grid
axis equal
Why I get only one arrow? I'd like to get an arrow each two x ticks.
Thank you very much in advance.

採用された回答

Jan
Jan 2017 年 11 月 12 日
You do not get only 1 arrow, but they all start from the same point and have the same size and direction. Try:
quiver(x, f, u, a)
  2 件のコメント
Gennaro Arguzzi
Gennaro Arguzzi 2017 年 11 月 12 日
編集済み: Gennaro Arguzzi 2017 年 11 月 12 日
Hello @JanSimon, how can I get the following result? Arrows are right scaled and not superimposed. This is the gradient in one dimension.
Thank you so much.
Jan
Jan 2017 年 11 月 12 日
x = -10:2:10;
f = -x.^2;
df = gradient(f, x);
figure;
plot(x, f);
hold on
quiver(x, zeros(size(x)), df/10, zeros(size(x)), 0, 'r');
Well, this is extremely ugly. I was not able to use quiver at any time for any useful output. There are many nice arrow functions in the FileExchange: https://www.mathworks.com/matlabcentral/fileexchange/?utf8=%E2%9C%93&term=arrow

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by