Differentiating a Symbolic Function

조회 수: 58 (최근 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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by