How can I differentiate an abstract symbolic function?

12 次查看(过去 30 天)
Hi, I would like to differentiate an abstract symbolic function in MATLAB.
To make sure we're all on the same page, let's say I have a function of two variables what's this where f is any function of one variable that is differentiable across its domain. Using partial differentiation, we should expect to see:
and
I've tried to use syms to observe this behaviour in MATLAB:
syms x y f(k) g(x,y)
g(x,y) = f(x - 3*y);
g_x = diff(g,x);
g_y = diff(g,y);
In effect, we find that
g_y = -3*D(f)(x - 3*y)
Which translates to after using the latex function.
But we also find that
g_x = diff(f(x - 3*y), x)
which translates to .
I have tried to use the expand and simplify functions on this result, but they don't seem to transform it into the expected . Is there a way for me to do this?
Note that if the coefficient of x was anything other than 1 or 0, then we have
g_x = c*D(f)(c*x - 3*y)

回答(2 个)

Star Strider
Star Strider 2021-8-4
I am not certrain that I understand what you want to do.
See if the diff documentation section on Differentiation With Respect to Function and Derivative will do what you want. It requires a slightly different syntax.
.
  2 个评论
c2332
c2332 2021-8-4
编辑:c2332 2021-8-4
I was trying to represent as since subtracting the two representations will not equal zero.
"I have tried to use the expand and simplify functions on this result, but they don't seem to transform it into the expected . Is there a way for me to do this?"
Star Strider
Star Strider 2021-8-4
I do not understand what you want to do. It appears that you want a specific format, and that format may not be available, unless you create it yourself.
.

请先登录,再进行评论。


Paul
Paul 2021-8-4
When I run this code (2019a) on my computer, I get:
syms x y f(k) g(x,y)
g(x,y) = f(x - 3*y);
g_x = diff(g,x)
g_y = diff(g,y)
g_x(x, y) =
D(f)(x - 3*y)
g_y(x, y) =
-3*D(f)(x - 3*y)
Is that not the form of the expected result? I'm confused if what you're asking about is the form of the result as sym objects, or the form of the typeset output from the Live Editor. If the latter, in my local version of Matlab I do get , although that desn't seem to be the case in 2021a, at least as run here:
g_x
g_x(x, y) = 
  4 个评论
c2332
c2332 2021-8-4
It's not just that issue. If I try performing
3*diff(f(x-3*y),x) + diff(f(x-3*y), y)
I should expect to get zero, but I get the following instead:
3*diff(f(x - 3*y), x) - 3*D(f)(x - 3*y)
Paul
Paul 2021-8-4
Something changed since 2019a. I just ran in 2020b and got:
g_x(x, y) =
diff(f(x - 3*y), x)

请先登录,再进行评论。

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by