-
Notifications
You must be signed in to change notification settings - Fork 0
Numerical analysis
yuuki edited this page Nov 27, 2024
·
1 revision
def lim(f):
"""Finds the limit of a given sequence."""
previous = f(1)
i = 1
while True:
current = f(2**i)
difference = abs(current - previous)
# If the absolute difference is less than the tolerance, assumes it has
# converged to the current value.
if difference < 1e-6:
return current
previous = current
i += 1
e = lim(lambda n: (1 + 1/n)**n)
print(f"{e:.5f}")
[show]
i |
f(2**i) |
difference |
---|---|---|
0 | 2.0000000 | |
1 | 2.2500000 | 2.50e-01 |
2 | 2.4414062 | 1.91e-01 |
3 | 2.5657845 | 1.24e-01 |
4 | 2.6379285 | 7.21e-02 |
5 | 2.6769901 | 3.91e-02 |
6 | 2.6973450 | 2.04e-02 |
7 | 2.7077390 | 1.04e-02 |
8 | 2.7129916 | 5.25e-03 |
9 | 2.7156320 | 2.64e-03 |
10 | 2.7169557 | 1.32e-03 |
11 | 2.7176185 | 6.63e-04 |
12 | 2.7179501 | 3.32e-04 |
13 | 2.7181159 | 1.66e-04 |
14 | 2.7181989 | 8.29e-05 |
15 | 2.7182404 | 4.15e-05 |
16 | 2.7182611 | 2.07e-05 |
17 | 2.7182715 | 1.04e-05 |
18 | 2.7182766 | 5.18e-06 |
19 | 2.7182792 | 2.59e-06 |
20 | 2.7182805 | 1.30e-06 |
21 | 2.7182812 | 6.48e-07 |
2.71828
🧸 Content is available under CC BY-SA 4.0 unless otherwise noted.