How can I differentiate an abstract symbolic function?
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 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)
0 commentaires
Réponses (2)
Star Strider
le 4 Août 2021
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 commentaires
Star Strider
le 4 Août 2021
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
le 4 Août 2021
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
4 commentaires
Paul
le 4 Août 2021
Something changed since 2019a. I just ran in 2020b and got:
g_x(x, y) =
diff(f(x - 3*y), x)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!