Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -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))
|
||||
|
|
@ -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())
|
||||
Loading…
Add table
Add a link
Reference in a new issue