Strange behaviour of a function handel
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi there,
I have constructed a function handle that reads like:
delta = 0.0173
L = 10555
H_f = @(k,N)1/2*((delta/k+L+N)-sqrt((delta/k+L+N)^2-4*L*N))
For values k=1 and very very very large numbers of N=1.e+40 the value that matlab throws up is zero. However, I can prove analytically that for any k>0, the limit of H_f as N-->inf is equal to L = 10555.
I would like to know what I am missing something or if I am doing sth wrong.
KR
댓글 수: 1
Stephen23
2021년 6월 12일
"I would like to know what I am missing something or if I am doing sth wrong."
You seem to be assuming that numeric mathematics (with limited precision) is the same as analytic mathematics or algebra.
It isn't.
Consider that each value has limited precision, and each operation accumulates floating point error.
채택된 답변
Steven Lord
2021년 6월 12일
According to Google Bill Gates has a net worth of 126.5 billion USD. If you saw him on the street and handed him a $20 bill, would that change his net worth?
Technically yes, it would. And if you were one of Bill Gates's accountants you might actually care. Maybe.
Practically no, it would not. You wouldn't say he had a net worth of 126.5 billion plus 20 USD. That $20 is negligible compared to $126.5 billion.
Why do I bring this up?
N = 1e40;
L = 1e6; % 1 million
N2 = N + L;
N == N2 % is N exactly equal to N2?
Relative to N, L is negligible. It's that $20 to Bill Gates.
In fact, the distance from N to the next largest number exactly representable in double precision is:
distanceToNextLargest = eps(N)
N == (N + distanceToNextLargest) % these two numbers are distinct
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!