Differentiating a Symbolic Function

18 ビュー (過去 30 日間)
Ammar Taha
Ammar Taha 2021 年 4 月 9 日
コメント済み: Star Strider 2021 年 4 月 9 日
If I have the following symbolic function:
syms f(x,y)
f(x,y) = 2*x^2 + y;
When I try to diff. this function w.r.t. (x) I get:
d = diff(f,x)
d(x, y) =
4*x
Which is a function in both x, and y NOT in (x) only.
How can I perform this and get the real exsisting function input only "i.e. (x) only here"?

採用された回答

Star Strider
Star Strider 2021 年 4 月 9 日
That is the corrct result, since diff is taking the partial derivative with respect to ‘x’ only, and ‘y’ is considered a constant.
To get the derivatives of ‘f’ with respect to both variables, use the jacobian function:
jf = jacobian(f)
producing:
jf(x, y) =
[4*x, 1]
See Differentiation for more information.
Although not appropriate here, explore the functionalDerivative function.
  4 件のコメント
Ammar Taha
Ammar Taha 2021 年 4 月 9 日
Ok, thats great. Thnaks a lot.
Star Strider
Star Strider 2021 年 4 月 9 日
As always, my pleasure!

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

その他の回答 (1 件)

Chendi Lin
Chendi Lin 2021 年 4 月 9 日
Hi Ammar,
Without explicitly defining the differentiation variable, "diff" uses the default variable, which is "x" in your case.
To get both derivatives, you can do
[diff(f(x,y),x) diff(f(x,y),y)]
And this should give you the correct result.
Thanks.
CD
  1 件のコメント
Ammar Taha
Ammar Taha 2021 年 4 月 9 日
Ok, thanks a lot.

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by