Effacer les filtres
Effacer les filtres

How to use binomial expansion to produce correct results?

2 vues (au cours des 30 derniers jours)
Muna Tageldin
Muna Tageldin le 3 Mar 2023
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 commentaires
Muna Tageldin
Muna Tageldin le 3 Mar 2023
@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 le 3 Mar 2023
Modifié(e) : Torsten le 3 Mar 2023
But what do you need the single summands for ? Since they change sign, they are no probabilities - thus they have no meaning.

Connectez-vous pour commenter.

Réponse acceptée

John D'Errico
John D'Errico le 3 Mar 2023
Modifié(e) : John D'Errico le 3 Mar 2023
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 commentaire
Muna Tageldin
Muna Tageldin le 3 Mar 2023
Modifié(e) : Muna Tageldin le 3 Mar 2023
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!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by