SIMPLE MATH ERROR CALCULATION
조회 수: 3(최근 30일)
표시 이전 댓글
I just need to do a simple math operation (9.2 x 9.2), wich result is 84.64. But somehow MATLAB give me a 84.699999999990 result I don't know why, I need the exact result of the operations because this result makes my servomotor go +90°, and wuth 84.64 it goes -90°.
q3b4=9.2^2;
q3b5=9.2*9.2;
Both q3b4 and q3b5 have the same result.

댓글 수: 0
답변(2개)
Sulaymon Eshkabilov
2021년 6월 13일
MATLAB's accuracy is not absolute and thus, such offsets will be present. You can select how many decimal digits you need using vpa() if you have Symbolic MATH toolbox.
https://www.mathworks.com/help/symbolic/digits.html#:~:text=By%20default%2C%20MATLAB%C2%AE%20uses,32%20digits%20by%20using%20digits%20.
댓글 수: 0
madhan ravi
2021년 6월 13일
편집: madhan ravi
2021년 6월 13일
Click on the tag floating-point
round((9.2^2 * 1e2) / 1e2, 3) % since you're using a hardware , not sure using a sym class would be acceptable for it
댓글 수: 0
참고 항목
범주
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!