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

조회 수: 26 (최근 30일)
moumene hafidh
moumene hafidh 2020년 2월 6일
댓글: moumene hafidh 2020년 2월 6일
CaptureTEST.PNG
  댓글 수: 1
Image Analyst
Image Analyst 2020년 2월 6일
What happens if you don't declare them as syms? Just don't declare them at all.

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

채택된 답변

Steven Lord
Steven Lord 2020년 2월 6일
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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by