How to symbolically differentiate a function with respect to a different function

Let's say I have the following defined as symbolic functions:
phi(t),
phi_dot(t),
alpha(t),
alpha_dot(t),
and I have the equation
x = phi_dot*cos(alpha)
I want to take the derivative of x with respect to phi_dot;
y = diff(x, phi_dot)
but I cannot do so without getting the error that follows:
Error using mupadmex
Error in MuPAD command: Invalid variable. [stdlib::diff]
Error in sym/diff (line 44)
R = mupadmex('symobj::diff', S.s, x.s, int2str(n));
I can easily differentiate with respect to time, for example. However, I need the partial derivative of the function with respect to, for example, phi_dot. The output I expect from the above example would be:
y = cos(alpha)
Can anyone help me?

 採用された回答

Alexander
Alexander 2012 年 6 月 12 日
It seems as if you cannot differentiate with respect to a symbolic function. Maybe it helps if you substitute phi_dot with a normal sym?
>> syms zz; y = diff(subs(x, phi_dot, zz), zz)
y(t) =
cos(alpha(t))

3 件のコメント

Peter
Peter 2012 年 6 月 12 日
Alexander,
That very well might work. I'll give it a shot and let you know.
Peter
Peter 2012 年 6 月 12 日
Thanks, Alex. I used the concept you suggested, using the subs() command to switch out the variables for functions of time, and I was thus able to take the time derivative of the equations.
Walter Roberson
Walter Roberson 2012 年 6 月 12 日
This solution is wrong!

サインインしてコメントする。

その他の回答 (2 件)

dmitry luchinskii
dmitry luchinskii 2018 年 1 月 18 日
編集済み: Walter Roberson 2018 年 1 月 18 日

1 投票

why would you try Functional Derivative of Vector of Functionals https://www.mathworks.com/help/symbolic/functionalderivative.html
Walter Roberson
Walter Roberson 2012 年 6 月 12 日

0 投票

If phi_dot is not independent of cos(alpha) then diff(phi_dot * cos(alpha)) with respect to cos(alpha) is not going to be cos(alpha)

3 件のコメント

Peter
Peter 2012 年 6 月 12 日
That's why I said diff(phi_dot*cos(alpha),phi_dot) was equal to cos(alpha).
You are right, differentiating with respect to cos(alpha) would yield a different result.
Walter Roberson
Walter Roberson 2012 年 6 月 12 日
Let phi_dot(t) = cos(alpha(t)) . Now differentiate phi_dot(t) * cos(alpha(t)) with respect to phi_dot(t) . You are differentiating phi_dot(t)^2 with respect to phi_dot(t) so the answer must be 2 * phi_dot(t) which would be 2 * cos(alpha(t)), which is *not* the same as cos(alpha(t))
You can only differentiate phi_dot(t) * cos(alpha(t)) with respect to phi_dot(t) and get cos(alpha(t)) if you know that phi_dot(t) is independent of cos(alpha(t)) -- and you have not given us any reason to expect that the two are independent.
You are failing to apply the product rule, http://en.wikipedia.org/wiki/Product_rule
Unlike the situation where variables are assumed to be independent, functions are not assumed to be independent in calculus.
Alexander
Alexander 2012 年 6 月 13 日
That sounds reasonable. That might be the reason why MuPAD refuses to differentiate w.r.t. phi_dot. I just assumed they are independent because that yielded the requested result.
You are right, Peter should double check that this is what he wants.

サインインしてコメントする。

質問済み:

2012 年 6 月 11 日

編集済み:

2018 年 1 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by