Why doesn't diff() recognise the second variable?

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!
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2018b

태그

질문:

2020년 6월 23일

댓글:

2020년 6월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by