Symbolic derivative of function using diff()
이전 댓글 표시
For those familiar, I am writing a function to find the EOMs using the lagrangian.
I have defined all variables as syms: x(t), y(t), z(t)...
Afterward, I define eqns KE and PE as functions of x,y, and z; and L = KE - PE.
When I call diff(L,x(t)) matlab returns the correct answer, but when attempting to take a second derivative with respect to time [diff(diff(L,x(t)),t)], Matlab calls the incorrect form of diff() and yields: "Error using sym/diff, [secondary] arguments must not be symbolic." Is there a way to force this command such that it yields a result? Happy to provide specific code on request, thank you.
답변 (2개)
Mahdi
2014년 5월 23일
Why don't you just tell diff to take the second derivative immediately? Look under the Higher-Order Derivatives subsection for diff.
In this case, you can do:
diff(L,x(t),2) % Second derivative
댓글 수: 6
Oscar Sandoval
2014년 5월 23일
Mahdi
2014년 5월 23일
Try
diff(L,x(t),t)
Also make sure that t is also defined as a symbol
syms t
Oscar Sandoval
2014년 5월 23일
Mahdi
2014년 5월 23일
Sorry, I'm trying to understand the problem itself here. Is t a defined set of numbers? Or is it just a symbol? Can you show me the definitions of x(t) and y(t) (what you made them equal to?)?
Oscar Sandoval
2014년 5월 23일
Mahdi
2014년 5월 26일
Sorry for the late reply,
I am afraid that I am not. I would suggest posting the question again and adding a bit more detail. Try searching the forums because I have run into this problem into the past and found a solution online.
Mischa Kim
2015년 6월 13일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!