MATLAB Answers

Symbolic differentiation with respect to first derivative

3 views (last 30 days)
madhan ravi
madhan ravi on 28 Dec 2019
Edited: madhan ravi on 28 Dec 2019
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

Sign in to comment.

Accepted Answer

Walter Roberson
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.

  1 Comment

madhan ravi
madhan ravi on 28 Dec 2019
Ah my bad it’s 1 , just made a mistake there . Thank you very much for all the explanations sir Walter:) it covered everything what I was hoping for.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2018b

Translated by