[Math] How to compute elliptic integrals in MATLAB

elliptic integralsintegrationMATLABnumerical methods

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*

Best Answer

Add in a power of 2, e.g.

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

Mathematica also verifies your results, and seems to need the power of 2 to agree with the book.

Related Question