How to plot gradients ?
8 ビュー (過去 30 日間)
古いコメントを表示
0 件のコメント
採用された回答
Star Strider
2020 年 10 月 1 日
14 件のコメント
Star Strider
2021 年 9 月 29 日
Yes, it is!
x = linspace(3, 4, 25);
y = linspace(5, 6, 25);
[X,Y] = meshgrid(x,y);
z = @(x,y) x.^2+y.^5+3*x+4*y;
Z = z(X,Y);
[px,py] = gradient(Z);
figure
contour(X,Y,Z)
hold on
quiver(X,Y,px,py)
hold off
.
Niklas Kurz
2022 年 3 月 13 日
編集済み: Niklas Kurz
2022 年 3 月 13 日
I would opt to normalise the Arrows for better scaling:
Norm = sqrt(px.^2+py.^2)
quiver(X,Y,px./Norm,py./Norm,0.5)
Otherwise the code is pretty neat!
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
