How can I differentiate a symbolic function?
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm in trouble with a problem and I couldn't find any solution for my specific case. I have this code:
syms l1 l2
f = xp
xp_l1 = diff(f,l1)
xp_l2 = diff(f,l2)
l1 and l2 are the two my independent variables depending on time, previously in the code i elaborate the expression of xp, that is dependent on l1 and l2 by a very complex expression. I need the partial derivatives, so i let matlab elaborate them, and it works. The problem come when i need to differentiate xp_l1 and xp_l2 by time. i tried in different ways but nothing allows me to obtain the differentiation automatically. This works but it is too complex and long
syms t l1(t) l2(t)
f = (5*l2(t))/4 - (5*l1(t))/2 + 5*l1(t)*(((200*l1(t) - 100*l2(t))/(25*(100*(l1(t))^2 - 100*l1(t)*l2(t) + 25*(l2(t))^2 + 4)) + ((200*l1(t) - 100*l2(t))*(- 100*(l1(t))^2 + 100*l1(t)*l2(t) - 25*(l2(t))^2 + 252))/(25*(100*(l1(t))^2 - 100*l1(t)*l2(t) + 25*(l2(t))^2 + 4)^2))/(4*((- 100*(l1(t))^2 + 100*l1(t)*l2 - 25*(l2(t))^2 + 252)/(2500*(l1(t))^2 - 2500*l1(t)*l2(t) + 625*(l2(t))^2 + 100))^(1/2)) + 1/2) - (5*l2(t)*(((200*l1(t) - 100*l2(t))/(25*(100*(l1(t))^2 - 100*l1(t)*l2(t) + 25*(l2(t))^2 + 4)) + ((200*l1(t) - 100*l2(t))*(- 100*(l1(t))^2 + 100*l1(t)*l2(t) - 25*(l2(t))^2 + 252))/(25*(100*(l1(t))^2 - 100*l1(t)*l2(t) + 25*(l2(t))^2 + 4)^2))/(4*((- 100*(l1(t))^2 + 100*l1(t)*l2(t) - 25*(l2(t))^2 + 252)/(2500*(l1(t))^2 - 2500*l1(t)*l2(t) + 625*(l2(t))^2 + 100))^(1/2)) + 1/2))/2 - (5*((- 100*(l1(t))^2 + 100*l1(t)*l2(t) - 25*(l2(t))^2 + 252)/(25*(100*(l1(t))^2 - 100*l1(t)*l2(t) + 25*(l2(t))^2 + 4)))^(1/2))/2
xp_l1_t= diff(f,t) % first derivative of wrt t
I wrote the dependance by t by hands. Are there any solutions to do it automatically?
댓글 수: 0
답변 (2개)
Bjorn Gustavsson
2019년 6월 17일
After doing this
syms t
syms l1(t)
syms l2(t)
f = ... % your rather lengthy expression
I had no problem getting an output from diff:
dfdt = diff(f,t)
...and I run a rather old version of matlab. Do you get an error or just no output? It wasn't necessary to split up the symbolic definitions either.
HTH
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!