採用された回答

Star Strider
Star Strider 2020 年 10 月 1 日

2 投票

14 件のコメント

qweasd
qweasd 2020 年 10 月 1 日
編集済み: qweasd 2020 年 10 月 1 日
thanks, I've seen this page but I still can't do it. I am new in Matlab.
Star Strider
Star Strider 2020 年 10 月 1 日
This should get you started:
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);
See the documentation section on Anonymous Functions to understand ‘z’.
You can also use ndgrid instead of meshgrid.
It is not a very interesting plot.
qweasd
qweasd 2020 年 10 月 1 日
Thank you, I will try it.
Star Strider
Star Strider 2020 年 10 月 1 日
My pleasure!
qweasd
qweasd 2020 年 10 月 2 日
I've been working on it, but still cant do it. I'm really bad :( If you don't mind, can you share the code?
Star Strider
Star Strider 2020 年 10 月 2 日
You aren’t really bad. You simply need to experiment with it.
The rest of the code is essentially what’s in the documentation example that I linked to, from the gradient call to the end of the example. You only need to make a few small changes to it.
qweasd
qweasd 2020 年 10 月 5 日
編集済み: qweasd 2020 年 10 月 5 日
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
Like this ?
Star Strider
Star Strider 2020 年 10 月 5 日
Like that!
The code I wrote for your problem:
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
They appear to match.
qweasd
qweasd 2020 年 10 月 5 日
thank you so much
Star Strider
Star Strider 2020 年 10 月 5 日
As always, my pleasure!
saurav Tiwari
saurav Tiwari 2021 年 9 月 29 日
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
saurav Tiwari
saurav Tiwari 2021 年 9 月 29 日
it's not working
Star Strider
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
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 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2020 年 10 月 1 日

編集済み:

2022 年 3 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by