[Scilab-users] Bernoulli numbers calculation

Samuel Gougeon sgougeon at free.fr
Thu Dec 30 21:17:48 CET 2021


Hello Lester,

Le 30/12/2021 à 08:59, Lester Anderson a écrit :
> Hello Samuel,
>
> Thanks for the solution. As pointed out it is best to show the 
> equation being assessed (from www.bernoulli.org 
> <http://www.bernoulli.org>). The one I looked at was the following:
>
> Explicit_formula.PNG
>
> Using nchoosek in the original code gives the same issue.


The inner sum over v is very prone to cumulative rounding errors:
The term v^n gets huge rapidly -- so is numerically truncated --,
while the (-1)^v term makes the sum alternate, which enhances residues...
that then mainly come from numerical truncations.
With n_max = 20, the maximum value of nchoosek(20,10)=184756
and is definitely not an issue. While even only 13^13
--> 13^13
  ans  =
    3.029D+14
is already not far from 1/%eps.
The recurrent implementation proposed earlier and based on
Bₘ =  -∑_k=0_→ m-1 (C_^k _m+1 ).B_k /(m+1)

\frac{-1}{m+1}{\sum _{{k=0}}^{{m-1}}{m+1 \choose k}B_k

has neither alternate terms nor huge power values that make a
direct computation numerically catastrophic.

Regards
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20211230/ab1965bf/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Explicit_formula.PNG
Type: image/png
Size: 13849 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20211230/ab1965bf/attachment.png>


More information about the users mailing list