Elliptic Integrals in Javascript

I just created a repo on github for computing complete elliptic integrals in javascript. The README.md is below, and a demo after that. You might ask yourself, “why would anybody want to compute elliptic integrals in javascript?” Stay tuned for an answer next week!


Complete elliptic integrals in javascript

Here I’ve implemented complete elliptic integrals of the first, second, and third kind in javascript. The implementation follows an iteration scheme based on the convergence of the arithmetic-geometric mean, which converges at least quadratically with number of iterations—therefore effectively doubling the number of digits each iteration. These iteration schemes come from Garrett, Milan Wayne, Journal of Applied Physics 34.9 (1963): 2567-2573, Eqs. (18)-(21).

The functions extend the Math object with:

  • Math.agm(a,g): arithmetic-geometric mean of two non-negative numbers
  • Math.EllipticK(m): Complete elliptic integral of the first kind
  • Math.EllipticE(m): Complete elliptic integral of the second kind
  • Math.EllipticPi(n,m): Complete elliptic integral of the third kind

The arguments are the parameter , which is related to the modulus via ; and the characteristic . The algorithms are valid for .

To be completely clear, the functions are computing the following integrals:

This agrees with the conventions of Mathematica.


Below, I used the code and JSXGraph to plot , and . Drag the slider to change the value of (release for JSXGraph to replot; it’s sampled sparsely while you drag).

Direct Link