# 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!

# elliptic-integrals-js

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 $m$, which is related to the modulus $k$ via $m=k^2$; and the characteristic $n$. The algorithms are valid for $% $.

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

This agrees with the conventions of Mathematica.

# Demo

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

Tags:

Categories:

Updated: