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

differentiationerrorfunctionsymbolicSymbolic Math Toolbox

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?

Best Answer

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))