필터 지우기
필터 지우기

Understanding Precision in Matlab

조회 수: 4 (최근 30일)
Ahmad Gad
Ahmad Gad 2020년 7월 1일
댓글: Walter Roberson 2020년 7월 1일
I have a simple question. How to split the different between the two numbers into 1e6 increment (unisg linspace)?
The numbers: 5.047639467288342e+4 and 5.047639467288343e+4.
Thanks
  댓글 수: 2
Stephen23
Stephen23 2020년 7월 1일
"How to split the different between the two numbers into 1e6 increment (unisg linspace)?"
You can't. There are no binary floating point numbers inbetween the two values that you gave.
We can confirm this very easily by noting that their hex representations differ only by 1:
>> A = 5.047639467288342e+4;
>> B = 5.047639467288343e+4;
>> num2hex(A)
ans = 40e8a58ca12906dd
>> num2hex(B)
ans = 40e8a58ca12906de
Ahmad Gad
Ahmad Gad 2020년 7월 1일
Thank you! Then, I have to consider changing the algorithm then.

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

답변 (1개)

Walter Roberson
Walter Roberson 2020년 7월 1일
You cannot do that with double precision.
If you have the symbolic toolbox then:
r = linspace(sym('5.047639467288342e+4'), sym('5.047639467288343e+4'), 1e6+1);
Note that the results will be symbolic numbers with higher precision than double(), so if you were to double() them, it would be with loss of precision
  댓글 수: 2
Ahmad Gad
Ahmad Gad 2020년 7월 1일
The code is numeric and those values will be inserted a matrix determinant function. I think it will be time consuming.
Walter Roberson
Walter Roberson 2020년 7월 1일
Determinants can have a lot of problems with cancellation. If you were to use symbolic numbers it would be better to use
r = linspace(sym(5.047639467288342e+4,'f'), sym(5.047639467288343e+4,'f'), 1e6+1);
However, symbolic determinants are slow. To put 1e6 numbers into an array you would need an array at least 1e3 x 1e3, and a proper accurate determinent of that would involve over 4 * 10^2567 terms.

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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by