# How to compute elliptic integrals in MATLAB

I need to calculate the complete elliptic integrals of the first and second kind , the incomplete elliptic integral of the first kind, and the incomplete elliptic integral of the second kind in MATLAB.

MATLAB has built in functions to calculate these functions, as I have shown in the links above, however I am not getting answers which are consistent with the book I am using (Handbook of Elliptic Integrals for Engineers and Scientists). The handbook has a table of values of k and the answer to the elliptic integral for that k. I'll give an example bellow:

K(k) = complete elliptic integral of the first kind

$$K(k) = \int_0^{2\pi} \frac {1}{\sqrt{1 - k^2 sin^2 \theta} }d\theta$$

Answers From The Book
(sin^-1)k     K        E
0 degrees    1.571    1.571
10 degrees   1.583    1.559
20 degrees   1.620    1.524
30 degrees   1.686    1.467
40 degrees   1.787    1.393


But if I use the MATLAB function it gives me different answers:

[K,E] = ellipke(sin(0*pi/180))
K = 1.5708
E = 1.5708

[K,E] = ellipke(sin(10*pi/180))
K = 1.6466
E = 1.5002

[K,E] = ellipke(sin(20*pi/180))
K = 1.7393
E = 1.4264

[K,E] = ellipke(sin(30*pi/180))
K = 1.8541
E = 1.3506

[K,E] = ellipke(sin(40*pi/180))
K = 1.9987
E = 1.2748


I understand that MATLAB uses a numerical method to calculate the elliptic integral because no analytical solution exists, so the answers cannot be completely accurate, but I would expect them to be better than this. At the moment they are way out.

The handbook also has a table of answers for all of the following:

E(k) = complete elliptic integral of the second kind

$$E(k) = \int_0^{2\pi} \sqrt{1 - k^2 sin^2 \theta }d\theta$$

F(ksi,k) = incomplete elliptic integral of the first kind

$$F(\xi,k) = \int_0^{\xi} \frac {1}{\sqrt{1 - k^2 sin^2 \theta} }d\theta$$

E(ksi,k) = incomplete elliptic integral of the second kind

$$E(\xi,k) = \int_0^{\xi} {\sqrt{1 - k^2 sin^2 \theta} }d\theta$$

And MATLAB gives completely wrong answers for all of these as well.

On the mathworks help page (shown in the link at the top of the page), the definition of the elliptic integrals look different to what they do in the handbook, so this might be the problem.

How can I fix this so that I get accurate answers?

Thanks!

*Note: I've tried decreasing the tolerance, but the answer always comes out the same. It's also worth noting that the answer to [K,E] = ellipke(sin(40*pi/180)), is very close to the answer for 53 degrees in the handbook for both K and E*

• Have you tried to check does substitution $t = \sin \theta$ for formulas at MathWorks page give same formulas as in your handbook? – Evgeny Jan 5 '14 at 15:09
• You have forgotten that you have to square the sine, so use: [K,E] = ellipke(sin(<degrees>*pi/180)^2), this gives you the correct answers. – Kwin van der Veen Jan 5 '14 at 15:17
• Here we have another example of the pitfall of the different notational conventions for an elliptic integral. – J. M. is a poor mathematician Feb 28 '18 at 17:00

[K,E] = ellipke(sin(10*pi/180)^2)

• you can add that this was mentioned (but not highlighted) in the matlab documentation. Matlab uses the parameter $m$, while Wolfram and wikipedia (and the OP handbook) use the elliptic modulus $k = \sqrt{m}$ – Federico Nov 24 '16 at 14:09