# Calculating relative error of Ramanujan formula for ellipse perimeter

On this page, they present the Ramajujan's second formula for the perimeter of an ellipse:

$$P \approx \pi (a+b) \left(1+ \frac{3 h}{\sqrt{4-3 h}+10}\right),$$

where $$h=(a-b)^2/(a+b)^2$$. They expand this formula as a power series of $$e^2$$, where $$e = \sqrt{1-b^2/a^2}$$ is the eccentricity, and claim that:

"All the terms match the correct series up to and including the coefficient of $$e^{18}$$."

This is slightly too difficult for my skills. I know I could use Series[f, {x, x0, n}], but I don't know the f.

How can I compare these two series with Mathematica?

We have to express a parameter $$h=(a-b)^2/(a+b)^2$$ in terms of the eccentricity of the ellipse $$e = \sqrt{1-b^2/a^2}$$.

Similarly we need comparing the second Ramanujan approximation for the perimeter of an ellipse $$\pi (a+b) \left(1+ \frac{3 h}{\sqrt{4-3 h}+10}\right)$$ (this should be divided by $$2\pi a$$ for comparison) with the first terms of the exact formula mentioned in the linked article:

Sum[-(1/(2 n - 1)) ((2 n)!/(2^n n!)^2)^2 e^(2 n), {n, 0, Infinity}]

(2 EllipticE[e^2])/Pi


The exact formula is the reason why elliptic integrals and elliptic functions are named of.

Now we should express $$h$$ in terms of $$e$$. Since $$\frac{b}{a}=\sqrt{1-e^2}$$ and $$a+b=a\left(1+\frac{b}{a}\right)$$ we can write

TeXForm[ f[e_] = 1/2 (1 + Sqrt[1 - e^2]) (1 + 3 h/(Sqrt[4 - 3 h] + 10)) /.{
h :> ((1 - Sqrt[1 - e^2])/(1 + Sqrt[1 - e^2]))^2} // Simplify]


$$\frac{1}{2} \left(\sqrt{1-e^2}+1\right) \left(\frac{3 \left(\sqrt{1-e^2}-1\right)^2}{\left(\sqrt{1-e^2}+1\right)^2 \left(\sqrt{\frac{-e^2+14 \sqrt{1-e^2}+2}{\left(\sqrt{1-e^2}+1\right)^2}}+10\right)}+1\right)$$ Now we have

Series[ f[e], {e, 0, 18}]

 1 - e^2/4 - 3/64 e^4 - 5/256 e^6 - 175/16384 e^8 - 441/65536 e^10
- 4851/1048576 e^12 - 14157/4194304 e^14 - 2760615/1073741824 e^16
- 8690825/4294967296 e^18


this clearly coincides up to $$e^{18}$$ with

Sum[-(1/(2 n - 1)) ((2 n)!/(2^n n!)^2)^2 e^(2 n), {n, 0, 9}] ==
Series[f[e], {e, 0, 18}] // Normal

True


Coefficients of $$e^{20}$$ and higher in the both series are also remarkably close.

{224570921 /137438953472, 112285459 /68719476736} // N[#, 9] &

{0.00163396850, 0.00163396848}


Edit

More generally we can exploit Asymptotic to elucidate accuracy of the second Ramanujan approximation. Let's define

Acc[r_] := Asymptotic[ f[e] - 2 EllipticE[e^2]/Pi, {e, 0, r}]

Acc[24]//N

-2.18279*10^-11 e^20 - 1.03682*10^-10 e^22 - 2.87372*10^-10 e^24


Let's find four largest (absolutely) coefficients of Acc up to range $$100$$:

TakeLargest[ N @ Abs @ CoefficientList[ Acc[100], e], 4]

{7.02274*10^-8, 6.84533*10^-8, 6.66395*10^-8, 6.47859*10^-8}


Yes, this is an outstanding approximation.

• Thank You very much! Commented May 8 at 14:30
• @Ytrewq You are welcome. Interesting question! Commented May 8 at 14:57
• Great! Just for completeness, an easy way to compute the ellipse perimeter in Mathematica is Perimeter[Disk[{0, 0}, {a, b}]] giving 4 b EllipticE[1 - a^2/b^2]. Commented May 9 at 17:20
• I wrote up a paper On the Perimeter of an Ellipse, published in The Mathematica Journal 11:2 (2009): wolframcloud.com/obj/abbott/Published/Mathematics/… Commented May 19 at 13:30