Strange behaviour of a function handel

1 view (last 30 days)
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 Comment
Stephen23
Stephen23 on 12 Jun 2021
"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.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 12 Jun 2021
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?
ans = logical
1
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)
distanceToNextLargest = 1.2089e+24
N == (N + distanceToNextLargest) % these two numbers are distinct
ans = logical
0

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!