Weird difference between matlab's evaluation of elliptic integral to my implementation
7 views (last 30 days)
Show older comments
Lucas Ruela
on 28 Mar 2024 at 16:01
Commented: Lucas Ruela
on 28 Mar 2024 at 16:33
I am evaluating the complete ellipitic integral of the first kind and I am comparing my implementation results with matlab's.
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?
2 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Special Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!