how many significant figures matlab uses?
조회 수: 30 (최근 30일)
이전 댓글 표시
i read that matlab uses 16 significant figures, but look at the picture below it show that matlab uses 16 significant figures, and then uses 17 significant figures, can anyone explain to me how many significant figures that matlab uses during the calculation and how many significant figures matlab stores in the memory, please dont give me links.
i am very confused can any one explain this topic to me simply because i need it for my college project.
댓글 수: 0
채택된 답변
Bruno Luong
2020년 11월 1일
편집: Bruno Luong
2020년 11월 1일
MATLAB does not work directly on digit. MATLAB uses IEEE 754 BINARY storage which is 52-bit (relative) precision.
Which is
>> 2^-52
ans =
2.2204e-16
>> eps(1)
ans =
2.2204e-16
It's somewhere between 15 and 16 digits.
The digit displayed on screen is just for human who use to digital numbers. It occur when user inquires the value on computer screen.
When display all screen you might see 16 or 17 digits by default in format long, but keep in mind it might be only an approximate of the binary coding.
And you can display even more. The numbers do not mean anything terribly meaningful after 16 digits. It just gives the exact digital conversion (up-to the last non-zero digit) of 52-bit of 2-radix coding
>> fprintf('%1.100f\n',pi)
3.1415926535897931159979634685441851615905761718750000000000000000000000000000000000000000000000000000
-----------------xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> fprintf('%1.100f\n',1/3)
0.3333333333333333148296162562473909929394721984863281250000000000000000000000000000000000000000000000
------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Whereas those trailing digits marked by xxxx matter, it's your appreciation. People throw them away because it's smaller than the quantification error. But the approximated value of 1/3 under MATLAB is actually
0.333333333333333314829616256247390992939472198486328125
(Note that any finite bit number in base 2 must be finite in base 10 since 2|10)
댓글 수: 3
Walter Roberson
2020년 11월 1일
A couple of months ago someone posted something that showed that in some cases you need 17 decimal digits to get the rounding right to the final bit.
Bruno Luong
2020년 11월 1일
편집: Bruno Luong
2020년 11월 1일
What does "get the rounding right to the final bit" exactly means?
I claim that for any double (x) in [0.5,1) this code always returns FALSE
num2digit=@(x)sprintf('%0.16f', x);
c0=num2digit(x);
c1=num2digit(x+eps(x));
isequal(c0,c1)
and this always returns TRUE
num2digit=@(x)sprintf('%0.16f', x);
c0=num2digit(x);
str2double(c0)==x
However if one consider to relax x bracket in [0.1,0.5) one need 17 digits to replicate x
x = 11/5/5
num2digit= @(x,n)reshape(sprintf(['%0.' num2str(n) 'f'], x),[],length(x))';
c16=num2digit(x,16) % '0.4400000000000001'
c17=num2digit(x,17) % '0.44000000000000006'
str2double(c16)==x % false
str2double(c17)==x % true
This is no surprise since
>> eps(x)
ans =
5.551115123125783e-17
So the last significant bit of x (=0.44000000000000006) is at 17 (fractional) digits
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!