MATLAB: Differentiation with respect to a derivative

matlab function

syms t q
q = some function of t
dq = diff(q)
d2q = diff(dq);
L = 6*q+3*dq+34
dL = diff(L,dq)
i want to compute diff of L with respect to dq ..Pls help me out

Best Answer

It is not possible to differentiate with respect to an expression.
You could do a change of variables, but you have to be very careful with doing that. If you have f(x) + g(dq) then you cannot treat that as diff(f(x),dq) + diff(g(dq),dq) because f(x) + g(dq) might together contribute parts that make up dq, giving you an interaction that you cannot see from f(x) or g(dq) alone. As soon as you start differentiating with respect to an expression, you can no longer treat additions as terms that you can differentiate independently.