vector partial derivative of a two variable function

7 ビュー (過去 30 日間)
fima v
fima v 2022 年 10 月 4 日
コメント済み: Star Strider 2022 年 10 月 4 日
Hello i have the following function which is dependant on two variables.
Is there a way to find the vector of the derivative with respect to x dz/dx(x,y) where x y are the vectors defined in the code?
Thanks.
x=[0:0.1:1];
y=[0:0.1:1];
z=x.^2+y.^2

回答 (1 件)

Star Strider
Star Strider 2022 年 10 月 4 日
Use the gradient function —
x=[0:0.1:1];
y=[0:0.1:1].';
z=x.^2+y.^2;
[Dx,Dy] = gradient(z)
Dx = 11×11
0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900 0.0100 0.0200 0.0400 0.0600 0.0800 0.1000 0.1200 0.1400 0.1600 0.1800 0.1900
Dy = 11×11
0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0100 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0200 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0400 0.0600 0.0600 0.0600 0.0600 0.0600 0.0600 0.0600 0.0600 0.0600 0.0600 0.0600 0.0800 0.0800 0.0800 0.0800 0.0800 0.0800 0.0800 0.0800 0.0800 0.0800 0.0800 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1000 0.1200 0.1200 0.1200 0.1200 0.1200 0.1200 0.1200 0.1200 0.1200 0.1200 0.1200 0.1400 0.1400 0.1400 0.1400 0.1400 0.1400 0.1400 0.1400 0.1400 0.1400 0.1400 0.1600 0.1600 0.1600 0.1600 0.1600 0.1600 0.1600 0.1600 0.1600 0.1600 0.1600 0.1800 0.1800 0.1800 0.1800 0.1800 0.1800 0.1800 0.1800 0.1800 0.1800 0.1800
figure
surf(x,y,z)
hold on
surf(x,y,Dx)
hold off
grid on
xlabel('X')
ylabel('Y')
text(x(end), y(1), Dx(1,end), ' \leftarrow Dx', 'Color','r')
In order to do this correctly, ‘z’ needs to be a matrix, so I transposed ‘y’ to create it as such.
.
  2 件のコメント
Torsten
Torsten 2022 年 10 月 4 日
Should be
[Dx,Dy] = gradient(z,0.1);
instead of
[Dx,Dy] = gradient(z)
Star Strider
Star Strider 2022 年 10 月 4 日
Noted. Correct.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by