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

5 次查看(过去 30 天)
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 个评论
Benjamin Großmann
Benjamin Großmann 2020-2-26
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).
Dev Sahu
Dev Sahu 2020-2-26
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-2-26
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 个评论
Dev Sahu
Dev Sahu 2020-2-26
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
Walter Roberson
Walter Roberson 2020-2-26
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by