Symbolic differentiation with respect to first derivative
3 views (last 30 days)
Show older comments
Is it possible to make a derivative of an equation with respective to the first derivative . Illustration:
syms x(t)
eqn = diff(x) - 2
%diff(eqn,diff(x))
The expected result is 1 [edited after sir Walters answer] . A workaround is using subs() but is there any other straightforward way to achieve the result?
0 Comments
Accepted Answer
Walter Roberson
on 28 Dec 2019
https://www.mathworks.com/help/symbolic/functionalderivative.html is the only available tool provided by Mathworks.
However, this is not going to do what you want:
syms x(t); dx = diff(x); eqn = dx - 2;
>> diff(eqn,dx)
Error using sym/diff (line 26)
Arguments, except for the first, must not be symbolic functions.
(which is a misleading error message that I will file a bug about.)
Note that if you would to have
eqn = x - 2
diff(eqn, x)
the result would be 1, not -2 . -2 is constant with respect to x(t) or diff(x,t) so it is going to vanish in the derivative.
It is tempting to use something like https://www.mathworks.com/help/symbolic/odetovectorfield.html to substitute the derivative with a symbol that you can then differentiate with respect to. However, drivatives are not independent of the original function, and you can arrive at wrong answers if you do this. I have posted examples in the past demonstrating that differentiating with one function with respect to another by processes like this give incorrect solutions (but that was a while ago and might be a bit tricky to locate now.) You cannot generally differentiate with respect to a function using normal calculus: you need The Calculus of Variations, which MATLAB does not implement.
More Answers (0)
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!