필터 지우기
필터 지우기

Help regarding "format long"

조회 수: 1 (최근 30일)
AR
AR 2011년 2월 26일
i am trying to solve a=(4:0.0002:4.20) with format long, but i am getting weird values and not accurated ones like 4.196000000000001 4.196200000000000 4.196400000000001 4.196600000000000 4.196800000000001
But it should be like this 4.196000000000000 4.196200000000000 4.196400000000000 4.196600000000000 4.196800000000000
why matlab is not giving me accurate answer and adding 0.000000000000001 at alternative figures.

채택된 답변

Matt Tearle
Matt Tearle 2011년 2월 26일
Welcome to the joy of round-off error. 0.0002 is not exactly representable in binary, hence adding these floating point numbers causes error at the level of machine precision. Enter eps(4) to see what machine precision is for these values.

추가 답변 (2개)

Jiro Doke
Jiro Doke 2011년 2월 26일
Take a look at this FAQ.

James Tursa
James Tursa 2011년 2월 26일
You may also find the num2strexact utility to be of some help in understanding this. e.g.,
>> num2strexact(4.196)
ans =
4.1959999999999997299937604111619293689727783203125
>> num2strexact(4.1962)
ans =
4.19620000000000015205614545266143977642059326171875
>>
You can find the num2strexact utility here:

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by