syms x(t) m1 m2
xr = x;
xl = 0;
T = (m1 * diff(xl)^2) / 2 + (m2 * (diff(xr)^2)) / 2 % why doesn't it recognise that xr is a function of time?
Why is the different from this?
T = (m1 * diff(xl,t)^2) / 2 + (m2 * (diff(xr,t)^2)) / 2 % gives the expected result
whereas if i do
diff(xr) % it gives me the correct result?
What is going on here?

 採用された回答

Star Strider
Star Strider 2020 年 6 月 23 日

1 投票

This works correctly in R2020a (Update 3):
syms x(t)
xr = x
diff(xr) % why doesn't it recognise that xr is a function of time?
T = diff(xr)
producing:
xr(t) =
x(t)
ans(t) =
diff(x(t), t)
T(t) =
diff(x(t), t)
I cannot reproduce the error.

4 件のコメント

madhan ravi
madhan ravi 2020 年 6 月 23 日
編集済み: madhan ravi 2020 年 6 月 23 日
Star could you try this and confirm ?
T = (m1 * diff(xl)^2) / 2 + (m2 * (diff(xr)^2)) / 2
Star Strider
Star Strider 2020 年 6 月 23 日
編集済み: Star Strider 2020 年 6 月 23 日
Sure!
syms x(t) m1 m2 xl(t)
xr = x;
T = (m1 * diff(xl)^2) / 2 + (m2 * (diff(xr)^2)) / 2
produces:
T(t) =
(m2*diff(x(t), t)^2)/2 + (m1*diff(xl(t), t)^2)/2
Note the additions to the syms call.
EDIT —
Adding the edited changes:
syms x(t) m1 m2
xr = x;
xl = 0;
T = (m1 * diff(xl)^2) / 2 + (m2 * (diff(xr)^2)) / 2
produces:
T(t) =
[ empty sym ]
most likely because the derivative of a scalar (without specifying the independent variable it is to be differentiated with respect to) does not exist:
Dxl = diff(xl)
produces:
Dxl =
[]
however:
Dxl = diff(xl,t)
produces:
Dxl =
0
.
madhan ravi
madhan ravi 2020 年 6 月 23 日
編集済み: madhan ravi 2020 年 6 月 23 日
Sorry for the mess Star, I had two tabs open used a wrong tab to submit the question, I mean for this one:
syms x(t) m1 m2
xr = x;
xl = 0;
T = (m1 * diff(xl)^2) / 2 + (m2 * (diff(xr)^2)) / 2 % it returns empty sym in my version :(
Produces:
T(t) =
[ empty sym ]
Edit: Ah now it's clear adding an empty array to another number gives an empty array, hence it was subtle and surprising.
Thank you Star!
Star Strider
Star Strider 2020 年 6 月 23 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Symbolic Math Toolbox についてさらに検索

製品

リリース

R2018b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by