Calulation in lim (1 + 1 /n) ^n when n -> infinite
Peter Pearson
pkpearson at nowhere.invalid
Mon Nov 9 12:51:34 EST 2015
On Mon, 9 Nov 2015 04:21:14 -0800 (PST), Salvatore DI DIO wrote:
>
> I was trying to show that this limit was 'e'
> But when I try large numbers I get errors
>
> def lim(p):
> return math.pow(1 + 1.0 / p , p)
>
>>>> lim(500000000)
> 2.718281748862504
>>>> lim(900000000)
> 2.7182820518605446 !!!!
Python floats have close to 16 decimal digits of precision. When you
compute 1+1/p with large p, the result will be close to 1, so digits of
1/p beyond the 16th place will be damaged by rounding. For p of
900000000, the first nearly-9 digits of 1/p are zero, so the first
"significant" digit is the 10th, and beyond the 16th digit -- the 7th
significant digit -- they're damaged, so you can only expect about
16-9 = 7 significant digits to be accurate. And as it turns out,
2.7182820518605446 is good to about 7 significant figures.
It takes longer to explain than to see: roundoff limits you to ...
(digits of p) + (good digits in the result) = 16 (approximately)
--
To email me, substitute nowhere->runbox, invalid->com.
More information about the Python-list
mailing list