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!