Weird difference between matlab's evaluation of elliptic integral to my implementation

7 views (last 30 days)
I am evaluating the complete ellipitic integral of the first kind and I am comparing my implementation results with matlab's.
Following Elliptic Integrals, developed two method to compute the integral, by integral and by agm.
The matlab version, I simply call ellipke. For example,
% matlabs
display(ellipke(0.5))
It returns 1.8541.
My integral method is this
b = integral(@(t) integrando(t,0.5),0,pi/2,'RelTol',0,'AbsTol',1e-12);
function r = integrando(t,k)
r = 1./sqrt(1-k.^2.*sin(t).^2);
end
The result is b = 1.6858. Quite different from matlab's.
The agm method is this
c = pi/2/agm(1,sqrt(1-0.5^2))
function r = agm(x0,y0,rel,maxtol)
arguments
x0 (1,1) double
y0 (1,1) double
rel (1,1) double = 1e-6
maxtol (1,1) double = 1000
end
a = x0;
g = y0;
count = 1;
while (a-g > rel && count < maxtol)
anext = (a+g)/2;
gnext = sqrt(a*g);
a = anext;
g = gnext;
end
r = (a+g)/2;
end
It also computes c = 1.6858. Exactly like the integral.
Why is there a differente between the results?

Accepted Answer

Torsten
Torsten on 28 Mar 2024 at 16:16
Moved: Torsten on 28 Mar 2024 at 16:18
You have to supply k^2, not k:
ellipke(0.25)
ans = 1.6858

More Answers (0)

Categories

Find more on Special Functions in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!