I am trying to substract variable c2(i) which contains 1.0000 from 1, but getting ambiguous output. Can someone suggest why "-4.4409e-16" instead of 0. Thanks for the help
K>> c2(i)
ans =
1.0000
K>> 1-c2(i)
ans =
-4.4409e-16

답변 (1개)

Jan
Jan 2017년 10월 21일
편집: Jan 2017년 10월 21일

0 개 추천

Welcome to the world of numerics with limited precision.
The result is not ambiguous, but expected and well defined. As you see, your c2(i) does not contain 1.0000, but this is the rounded output for the command window only. The values of 1.0 and c2(i) differ by -4.4409e-16, exactly as Matlab tells you. The "ambiguous" part is only, that the value of c2(i) is displayed as 1.0 . Try this:
fprintf('%.17g', c2(i))

카테고리

도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

질문:

2017년 10월 21일

편집:

Jan
2017년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by