Numerical errors of basic multiple

조회 수: 15 (최근 30일)
yifwang
yifwang 2019년 8월 26일
댓글: yifwang 2019년 8월 26일
When using matlab multiple calculation, some errors happen
a = 7*13e-6;
b = 6*13e-6;
the answer is
a = 9.09999999999999999e-5
b = 7.80000000000000000e-5
erroe happened at a but not at b;
So how this error happen and how * works? On what condition the error happen?
  댓글 수: 2
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 26일
Error?
>> a =13e-6
a =
1.300000000000000e-05
>> 7*a
ans =
9.099999999999999e-05
yifwang
yifwang 2019년 8월 26일
7*13e-6 should be exactly
9.100000000000000e-5
but not
9.099999999999999e-5
error

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

채택된 답변

Ted Shultz
Ted Shultz 2019년 8월 26일
These are floating point calculations. Not every number can be represented, and this rounding error can compound when you do math with these imperfect numbers.
"Floating-point error arises because real numbers cannot, in general, be accurately represented in a fixed space."

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by