help me ...cos and sin value not correct ! whay

31 views (last 30 days)
CaptureTEST.PNG
  1 Comment
Image Analyst
Image Analyst on 6 Feb 2020
What happens if you don't declare them as syms? Just don't declare them at all.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 6 Feb 2020
Line 1 is completely unnecessary, since line 2 overwrites those symbolic variables with numeric values.
I'm assuming your trotx and trotz functions call sin and/or cos internally, since there are no actual calls to the trigonometric functions in the code you've shown.
pi is not π. It's close, but your computer doesn't have enough memory to store the exact value of the transcendental number π.
Here are a few potential solutions. I'd probably use sind and cosd.
1) Use sind and cosd (introduced before release R2006a) or sinpi and cospi (introduced in release R2018b) instead of taking the sin or cos of a multiple of 2*pi/360.
>> cos(-90*2*pi/360)
ans =
6.1232e-17
>> cosd(-90)
ans =
0
>> cospi(-90*2/360)
ans =
0
2) Define a1 to be a symbolic variable with the value -90. This would combine and replace lines 1 and 2 assuming you did the same thing for c1, Q2, and d2. In that case, MATLAB will compute a1*2*pi/360 symbolically rather than numerically.
>> a1 = sym(-90);
>> cos(a1*2*pi/360)
ans =
0

More Answers (0)

Community Treasure Hunt

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

Start Hunting!