How to use binomial expansion to produce correct results?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muna Tageldin
el 3 de Mzo. de 2023
Editada: Muna Tageldin
el 3 de Mzo. de 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 comentarios
Respuesta aceptada
John D'Errico
el 3 de Mzo. de 2023
Editada: John D'Errico
el 3 de Mzo. de 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 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Numbers and Precision en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!