MATLAB: How can i differentiate diff(q(t), t) again

differential equationsmathematicsMATLABmatlab functionsymbolicSymbolic Math Toolbox

Hello..
I started to compute a function which has a variable depending on time which I defined as q(t). In the computation, the variable was differentiated and I ended up with diff(q(t), t). Now I want to further differentiate this resulting function wrt diff(q(t), t) i.e. q' but when I wrote "diff(exp3, diff(q(t), t));" matlab showed an error: "Second argument must be a variable or a nonnegative integer specifying the number of differentiations".
Can anybody help me figure this out.
So far I have tried to use functionalDerivative but that doesnt seem to work as well. Also I have found a way around this: I can use the sub function to substitute diff(q(t), t)) by qdot and do this diff(exp3, qdot); but that isnt what I intend to do.
Please Help.

Best Answer

You cannot differentiate with respect to a function in normal calculus, only with respect to a variable. Differentiating with respect to a function requires Calculus of Variations.
People often propose that you substitute a variable for the function and differentiate with respect to that. However a number of years ago I posted an example of a case where that would produce the wrong answer. Unfortunately it was long enough ago that it would be difficult to find the post.