How can i differentiate diff(q(t), t) again?

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.

3 Comments

EDIT: I dont want to differentiate wrt time. I want to differntiate my equation wrt q' i.e. diff(q(t), t). So lets say that my function is f= a*q(t) and I perform diff(f, t), I will end up with f' = a*diff(q(t), t). Now I want to differentiate this f' further but not wrt time but wrt q' i.e. diff(q(t), t).
Thankyou
Sorry, i got you wrong so i deleted my Answer.
As compensation for my misunderstanding I prepared a MWE. Is this rebuilding your problem?
clearvars, close all
clc
syms q(t)
exp = q(t).^2;
exp2 = diff(exp,t);
Ouput of exp2 is
exp2 = 2*q(t)*diff(q(t), t)
Now, we want to differentiate exp2 w.r.t. diff(q(t),t).
Yes, Exactly, I worked this out by using subs() and replaced diff(q(t), t) with qdot(t) and differentiated it.
So now instead of exp2 = 2*q(t)*diff(q(t), t) its now exp2 = 2*q(t)*qdot(t);
Hence insead of differentiating wrt diff(q(t),t) I differentiated wrt qdot(t) which is what Walter suggested below. That seems to work but i dont really know if thats the correct way of doing this.

Sign in to comment.

 Accepted 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.

2 Comments

I am working with Lagrange Eqautions and hence I need to differentiate this way. I already used the idea of subsitution by a variable but I was not really sure if that was the right way. Hence wanted to know if there was a better way around this problem
I found the post ;-)
https://www.mathworks.com/matlabcentral/answers/40904-how-to-symbolically-differentiate-a-function-with-respect-to-a-different-function#comment_84171 shows an example where substituting a variable for a function would fail to produce the right answer.
When you substitute a variable for an unknown function, and differentiate with respect to the variable, then you assume that there is an independence between terms that you simply cannot be sure of because the function is unknown.
Proceeding by substituting a variable has the potential to produce some function that satisfies the other conditions and is independent enough that the derivative holds, but it cannot be assumed that the independence will definitely hold true: at the very least you need to back-substitute and check that the derivative did work out.

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2017a

Community Treasure Hunt

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

Start Hunting!