i am trying to put my level curves and gradient vectors on same figure but i can't

3 ビュー (過去 30 日間)
well, it is a simple question i am new in MATLAB. i cannot put my gradient vectors and level curves on same figure, please help me.
here is my code.
f=@(x,y) 16*y.^2 + 9*x.^2;
g= gradient(f, [x, y])
figure(1)
[X, Y] = meshgrid(-1:.1:1,-1:.1:1);
z=f(X,Y);
contour(X,Y,z,[0:10])
G1 = subs(g(1), [x y], {X,Y});
G2 = subs(g(2), [x y], {X,Y});
quiver(X, Y, G1, G2)

採用された回答

Star Strider
Star Strider 2019 年 4 月 20 日
Your current approach is not going to work.
Try this instead:
f=@(x,y) 16*y.^2 + 9*x.^2;
g = @(z) gradient(z)
figure(1)
[X, Y] = meshgrid(-1:.1:1,-1:.1:1);
z=f(X,Y);
contour(X,Y,z,[0:10])
hold on
[G1,G2] = gradient(z);
quiver(X, Y, G1, G2)
hold off
axis equal
Experiment to get the result you want.
  2 件のコメント
Kuatra Patil
Kuatra Patil 2019 年 4 月 20 日
that is amazing man thanks!
Star Strider
Star Strider 2019 年 4 月 20 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by