フィルターのクリア

How to use binomial expansion to produce correct results?

6 ビュー (過去 30 日間)
Muna Tageldin
Muna Tageldin 2023 年 3 月 3 日
編集済み: Muna Tageldin 2023 年 3 月 3 日
Hi, I'm working on numerical problems where I need to calculate the cumulative distribution function values using summation. Furthermore, my code utilizes binomial expansion like the following
I wrote a function to compute CDF values using bionomial expansion
function results = sum_testing(mu,z,n)
for i = 1:n+1
t= nchoosek(n,i-1);
results(i) = t.*(-1).^((n-i+1)).*exp(-u*(z).*(n-i+1))
end
My problem is that, for large n's (n>100), the CDF values are very large (1e+60). How can I modify the above code to produce accurate results (using bionomial expansion)?
  3 件のコメント
Muna Tageldin
Muna Tageldin 2023 年 3 月 3 日
@Torsten This series is a simplified example of what I'm trying to calculate. The function that I'm dealing with has similar structure (bionomial expansion) with large n's and lots of calculations.
Torsten
Torsten 2023 年 3 月 3 日
編集済み: Torsten 2023 年 3 月 3 日
But what do you need the single summands for ? Since they change sign, they are no probabilities - thus they have no meaning.

サインインしてコメントする。

採用された回答

John D'Errico
John D'Errico 2023 年 3 月 3 日
編集済み: John D'Errico 2023 年 3 月 3 日
How? Using double precision arithmetic? You often can't. You need to remember that double preciion arithmetic lives in 16 significant digits (roughly). So adding and subtracting numbers that differ by more than 16 powers of 10 will yield numerical garbage.
In some cases, you can succeed by the use of logs to compute individual terms, if there would otherwise be an underflow or an overflow, but then multiplying a very large number by a very small one would result in something managable.
You can't just assume a computer can compute anything you throw at it. You might decide that using higher precision is warranted. So you might do those computations using syms and vpa, or perhaps a high precision float tool like my HPF toolbox. But beware that any such solution, while it can succeed, will generally be exceedingly slow. This is the price you must pay. Or, spend some time in learning good numerical methods for solving such problems, which would generally teach you pretty much what I said above.
  1 件のコメント
Muna Tageldin
Muna Tageldin 2023 年 3 月 3 日
編集済み: Muna Tageldin 2023 年 3 月 3 日
Aha, I actually missed this point. I tried the syms and it worked (it's actually faster). Thanks. I will look at the HPF toolbox as well!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by