Differentiate with Respect to Derivative

1 回表示 (過去 30 日間)
Mitra Taghizadeh
Mitra Taghizadeh 2022 年 9 月 12 日
コメント済み: Mitra Taghizadeh 2022 年 9 月 13 日
Hi,
I have this code:
syms x(t) m k t
T = m/2*diff(x(t),t)^2;
D1 = diff(T,diff(x(t), t))
But I got this error:
Second argument must be a variable or a nonnegative integer specifying the number of differentiations.
Do you know how can I have the differentiate with respect to derivative?!

回答 (1 件)

David Goodmanson
David Goodmanson 2022 年 9 月 12 日
Hello Mitra,
what version of Matlab are you running? Running your code in 2021b gives
D1 =
m*diff(x(t), t)
as desired. Running it in 2019b gives the error message that you have. So there must have been some improvements in the interim. The following workaround, though, runs in 2019b and gives the correct result:
syms x(t) m k t dxdt
T = m/2*diff(x(t),t)^2;
T = subs(T,diff(x(t),t),dxdt);
D1 = diff(T,dxdt);
D1 = subs(D1,dxdt,diff(x(t),t))
D1 =
m*diff(x(t), t)
  1 件のコメント
Mitra Taghizadeh
Mitra Taghizadeh 2022 年 9 月 13 日
Thank you David. It works.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by