higher-accuracy-integrals / MES /ref_ellipse_mpmath.py
perrabyte's picture
Upload 270 files
96cca27 verified
Raw History Blame Contribute Delete
670 Bytes
import mpmath
# 1. Set your arbitrary decimal precision (e.g., 50 digits)
mpmath.mp.dps = 50
def ellipse_circumference_exact(a, b):
# Convert inputs to mpmath high-precision floats
a = mpmath.mpf(a)
b = mpmath.mpf(b)
# Calculate eccentricity squared: m = 1 - (b^2 / a^2)
m = 1 - (b**2 / a**2)
# Exact Formula: C = 4 * a * E(m)
# Note: mpmath.ellipe takes parameter m (eccentricity squared)
return 4 * a * mpmath.ellipe(m)
# Example usage
a_axis = 5.0
b_axis = 3.0
C = ellipse_circumference_exact(a_axis, b_axis)
print(C)
# Outputs exactly 50 decimal places of accuracy:
# 25.526998863398131362241641031331826065576269229712