Symbolic Math Toolbox - Derive a function with respect to another function

조회 수: 1 (최근 30일)
mistajojo
mistajojo 2014년 10월 23일
답변: Joan Sans 2018년 6월 26일
Hello,
i want to verify a calculation I did already on paper. There the following problem occurs:
>> clear all
>> syms t x(t)
>> f=3*x
>> diff(f,x)
Error using sym/diff (line 26)
All arguments, except for the first one, must not be symbolic functions.
I want to derive a funtion woth respect to another function of time. And i even need the derivation of a function with respect to another derivative of a function of time.
I need this because I want to get the equations of motion of a system by using Lagrange equations of the second kind .
Can anybody help me with this problem? Thanks a lot. Johannes

답변 (2개)

Zoltán Csáti
Zoltán Csáti 2014년 10월 23일
편집: Zoltán Csáti 2014년 10월 23일
I also bumped into this question when I wanted to create the equation of motion using this method. Matlab's Symbolic Math Toolbox uses the Maple engine, so you can try the following: Physics:diff(L(t), ydot(t)), where L(t) is the Lagrangian that you want to differentiate with respect to the time derivative of coordinate y(t). I stress again, that this code is in Maple. As I see from your error message, it can't be done in Matlab. Therefore use Maple or do it by hand.
  댓글 수: 2
mistajojo
mistajojo 2014년 10월 23일
I found solve it in matlab. Maybe it's not the best way, but it works anyway. The solution is to substitute x(t) by another variable. I built a own function which does this:
function [f_out] = diff2(f_in,ableiten)
syms substitute;
f_zwischen=subs(f_in,ableiten,substitute);
f_zwischen_diff=diff(f_zwischen,substitute);
f_out=subs(f_zwischen_diff,substitute,ableiten);
end
But be careful. For some reason it only works properly if it is typed like this:
diff2(f,x(t))
If it is typed like the following statement it wont work properly !
diff2(f,x)

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


Joan Sans
Joan Sans 2018년 6월 26일
it works perfect! Thanks

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by