Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,16 @@
from math import sqrt
def agm(a0, g0, tolerance=1e-10):
"""
Calculating the arithmetic-geometric mean of two numbers a0, g0.
tolerance the tolerance for the converged
value of the arithmetic-geometric mean
(default value = 1e-10)
"""
an, gn = (a0 + g0) / 2.0, sqrt(a0 * g0)
while abs(an - gn) > tolerance:
an, gn = (an + gn) / 2.0, sqrt(an * gn)
return an
print agm(1, 1 / sqrt(2))

View file

@ -0,0 +1,10 @@
from decimal import Decimal, getcontext
def agm(a, g, tolerance=Decimal("1e-65")):
while True:
a, g = (a + g) / 2, (a * g).sqrt()
if abs(a - g) < tolerance:
return a
getcontext().prec = 70
print agm(Decimal(1), 1 / Decimal(2).sqrt())