フィルターのクリア

Strange behaviour of a function handel

1 回表示 (過去 30 日間)
Rubén Pérez Sanz
Rubén Pérez Sanz 2021 年 6 月 12 日
回答済み: Steven Lord 2021 年 6 月 12 日
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
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
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?
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by