[Scilab-users] Computing with very large numbers in Scilab
Pinçon Bruno
bruno.pincon at univ-lorraine.fr
Thu Jan 1 17:47:48 CET 2015
Le 01/01/2015 17:08, Rafael Guerra a écrit :
> Dear Scilab'ers,
>
> Happy New Year.
> Does someone know to perform in Scilab computations involving very large
> numbers?
> For example, the how to compute the following probability formula:
> 1-365!/((365-23)! *365^23)
>
> 1-factorial(365)/(factorial(365-23)* 365^23) produces Nan in Scilab
> The correct answer (using Wolfram Alpha) is: 0.507...
>
You should work around the formula such that too large numbers are
avoided.
In your case it is easy :
365!/((365-23)! *365^23) =
((365-22)*(365-21)*.......*(365-0))/(365 * 365 * ..... * 365)
= (343/365)*(344/365)*....*(364/365)*(365/365)
In scilab this can be coded this way :
1 - prod( (343:364)/365 )
hth
B.
More information about the users
mailing list