MATLAB Answers

Birdman
0

Strange behavior of diff function with symbolic variables

Birdman
さんによって質問されました 2019 年 2 月 20 日
最新アクティビティ Birdman
さんによって コメントされました 2019 年 2 月 20 日
Hello everyone,
There is a strange behavior that I encountered while using diff function with symbolic variables, not functions.
Consider the following symbolic expression:
syms theta1
D=0.31*cos(theta1)^2
diff(D,theta1)
>>
-0.62*cos(theta1)*sin(theta1)
This works as expected but when the expression becomes complicated like
syms theta1 theta2 theta3
D=0.31*cos(theta1)^2 - 2.7e-4*sin(theta2) - 0.88*sin(theta2)*(7.3e-5*cos(theta2) - 0.011*sin(theta2) + 3.1e-4) - 0.88*cos(theta2)*(7.3e-5*sin(theta2) - 4.2e-3*cos(theta2) + 4.6e-4) - 1.0*(0.48*sin(theta3) - 0.88*cos(theta2)*cos(theta3))*(5.1e-4*cos(theta3) - 1.7e-4*sin(theta2) - 0.047*sin(theta3) + 0.088*cos(theta2)*cos(theta3) + 9.5e-4*cos(theta2)*sin(theta3)) - 4.1e-4*cos(theta2) + 0.88*sin(theta2)*(3.2e-4*cos(theta3) + 0.073*sin(theta2) + 9.0e-5*sin(theta3) - 1.7e-4*cos(theta2)*cos(theta3) + 5.9e-4*cos(theta2)*sin(theta3)) + 0.31*sin(theta1)^2 + 1.0*(0.48*cos(theta3) + 0.88*cos(theta2)*sin(theta3))*(0.035*cos(theta3) + 5.9e-4*sin(theta2) - 5.1e-4*sin(theta3) + 9.5e-4*cos(theta2)*cos(theta3) + 0.064*cos(theta2)*sin(theta3)) + 0.33;
diff(D,theta1)
>>
0
I receive zero. What is the cause for this? Appreciate your help.

  0 件のコメント

サインイン to comment.

製品


リリース

R2017b

1 件の回答

回答者: Yasasvi Harish Kumar 2019 年 2 月 20 日
 採用された回答

Hi,
Your expression, D contains only 2 theta1 terms(in bold) whose derivatives cancel each other. Differentiation of theta2 and theta3 wrt theta1 is zero. Therefore your answer is zero.
D =0.31*cos(theta1)^2 - 2.7e-4*sin(theta2) - 0.88*sin(theta2)*(7.3e-5*cos(theta2) - 0.011*sin(theta2) + 3.1e-4) - 0.88*cos(theta2)*(7.3e-5*sin(theta2) - 4.2e-3*cos(theta2) + 4.6e-4) - 1.0*(0.48*sin(theta3) - 0.88*cos(theta2)*cos(theta3))*(5.1e-4*cos(theta3) - 1.7e-4*sin(theta2) - 0.047*sin(theta3) + 0.088*cos(theta2)*cos(theta3) + 9.5e-4*cos(theta2)*sin(theta3)) - 4.1e-4*cos(theta2) + 0.88*sin(theta2)*(3.2e-4*cos(theta3) + 0.073*sin(theta2) + 9.0e-5*sin(theta3) - 1.7e-4*cos(theta2)*cos(theta3) + 5.9e-4*cos(theta2)*sin(theta3)) + 0.31*sin(theta1)^2 + 1.0*(0.48*cos(theta3) + 0.88*cos(theta2)*sin(theta3))*(0.035*cos(theta3) + 5.9e-4*sin(theta2) - 5.1e-4*sin(theta3) + 9.5e-4*cos(theta2)*cos(theta3) + 0.064*cos(theta2)*sin(theta3)) + 0.33;
I hope I could help.
Regards

  1 件のコメント

Birdman
2019 年 2 月 20 日
My bad. Thank you.

サインイン to comment.



Translated by