필터 지우기
필터 지우기

Why does this algorithm yield an 'incorrect' result?

조회 수: 1 (최근 30일)
Lewis
Lewis 2022년 1월 18일
편집: DGM 2022년 1월 18일
The following code yields cumul_total = 2.000000000026658e+05 . What is the '26658' on the end? Why does this occur?
Thank you
A = (0.2);
cumul_total = (0.0);
for iii = 1:1e6
cumul_total = cumul_total + A;
end
cumul_total

채택된 답변

DGM
DGM 2022년 1월 18일
편집: DGM 2022년 1월 18일
This is a consequence of accumulating the small errors inherent to floating-point representations of numbers.
A = 0.2;
S = 0;
% watch the error
format long
for k = 1:100
S = S+A
end
Note the remarks on accuracy and pitfalls here.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by