Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MATLAB computes Incomplete Elliptic Integrals incorrectly?

Subject: MATLAB computes Incomplete Elliptic Integrals incorrectly?

From: Ishan Sharma

Date: 24 Apr, 2010 11:11:05

Message: 1 of 6

I compute the Incomplete Elliptic Function of the second kind in both MATLAB and Maple. For some values, I obtain an exact match, but not so for others. Please see below:

CASE 1: Perfect match
MATLAB output
> mfun('EllipticE',sqrt(1-.4^2),sqrt((1-.6^2)/(1-.4^2)))
> ans = 0.9863

MAPLE13 output: 0.9863238216

CASE 2: No match.
MATLAB output
> mfun('EllipticE',sqrt(1-.4^2),sqrt((1-.5^2)/(1-.4^2)))
> ans = 1.4182

MAPLE13 output: 0.9495803244

Can someone throw light on this?

Thanks!

ishan

Subject: MATLAB computes Incomplete Elliptic Integrals incorrectly?

From: Walter Roberson

Date: 24 Apr, 2010 13:56:32

Message: 2 of 6

Ishan Sharma wrote:
> I compute the Incomplete Elliptic Function of the second kind in both
> MATLAB and Maple. For some values, I obtain an exact match, but not so
> for others. Please see below:
>
> CASE 1: Perfect match
> MATLAB output
>> mfun('EllipticE',sqrt(1-.4^2),sqrt((1-.6^2)/(1-.4^2)))
>> ans = 0.9863
>
> MAPLE13 output: 0.9863238216
>
> CASE 2: No match.
> MATLAB output
>> mfun('EllipticE',sqrt(1-.4^2),sqrt((1-.5^2)/(1-.4^2)))
>> ans = 1.4182
>
> MAPLE13 output: 0.9495803244
>
> Can someone throw light on this?

You are mixing floating point numbers and exact numbers, which often
leads to problems. You might get a different result (or not) if you were
to use something like,

mfun('EllipticE', sqrt(1-sym('4/10')^2),
sqrt((1-sym('6/10')^2)/(1-sym('4/10')^2)))

I converted a 10th order series of EllipticE with the same first
argument, and the second near 9/10 (one of your second arguments is
below that, the other above that). Some large numbers are involved --
large enough to present precision problems if the second argument was
not too much bigger (relatively.) Even so, the default 10 digits of
precision within mfun are enough that one can clearly see that in that
range of values, the curve approximates linear fairly closely, which the
Maple 13 answer is consistent with and the MuPad answer is not.

I would thus say that you have found a bug.

Subject: MATLAB computes Incomplete Elliptic Integrals incorrectly?

From: Roger Stafford

Date: 24 Apr, 2010 19:11:05

Message: 3 of 6

"Ishan Sharma" <sudden20@yahoo.com> wrote in message <hqujk9$7o2$1@fred.mathworks.com>...
> I compute the Incomplete Elliptic Function of the second kind in both MATLAB and Maple. For some values, I obtain an exact match, but not so for others. Please see below:
>
> CASE 1: Perfect match
> MATLAB output
> > mfun('EllipticE',sqrt(1-.4^2),sqrt((1-.6^2)/(1-.4^2)))
> > ans = 0.9863
>
> MAPLE13 output: 0.9863238216
>
> CASE 2: No match.
> MATLAB output
> > mfun('EllipticE',sqrt(1-.4^2),sqrt((1-.5^2)/(1-.4^2)))
> > ans = 1.4182
>
> MAPLE13 output: 0.9495803244
>
> Can someone throw light on this?
>
> Thanks!
>
> ishan
----------
  I don't know the parameters MAPLE13 uses for elliptic integrals but you should check on it. Even within Mathworks there are two conflicting definitions used. Here are two excerpts from Mathworks manuals:

ellipke:
"Some definitions of K and E use the elliptical modulus k instead of the
parameter m. They are related as k^2 = m."

EllipticE(x,k):
"This definition uses modulus k. The numerical ellipke function and the MuPAD functions for computing elliptic integrals use the parameter m = k^2."

  Also I would advise you to display your matlab results to a higher accuracy by using 'format long', so the comparisons will be more valid. You might find that your "perfect match" was not so perfect.

Roger Stafford

Subject: MATLAB computes Incomplete Elliptic Integrals incorrectly?

From: Roger Stafford

Date: 24 Apr, 2010 21:55:24

Message: 4 of 6

  After consulting some old tables of elliptic integrals I agree with Walter. The answer 1.4182 you quote as being given by 'EllipticE' is way off the correct value for the arguments you state you have given it. That answer would only be correct for a k value well below .6 and an x value much closer than yours to 1. After double checking your answers you should report this to Mathworks.

Roger Stafford

Subject: MATLAB computes Incomplete Elliptic Integrals incorrectly?

From: moiseev.igor

Date: 27 Apr, 2010 22:36:18

Message: 5 of 6

You may try to use the "elliptic12" function from the elliptic package
http://elliptic.googlecode.com/

Just get the single file elliptic12.m, put it in your PATH and it
gives the results for incomplete ellip. integrals F and E.

The only difference with Maple is that it calculates the integrals
with different to maple representation,
check the sample code for "asin" and square of "sqrt((1-.6^2)/(1-.
4^2))" to obtain the same results!

> > mfun('EllipticE',sqrt(1-.4^2),sqrt((1-.6^2)/(1-.4^2)))
> > ans =  0.9863

[F,E] = elliptic12(asin(sqrt(1-.4^2)),(1-.5^2)/(1-.4^2))
F =
   1.474960073006188
E =
   0.949580324404286

Subject: MATLAB computes Incomplete Elliptic Integrals incorrectly?

From: Daniel

Date: 7 Dec, 2011 19:01:10

Message: 6 of 6

Can I ask how well this package has been validated?
Being the only (if not the only) full elliptic function package in Matlab which is available to my knowledge, I wanted to know how well it works? ... feedback from users etc...? Couldn't find much about this online...

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us