Weird difference between matlab's evaluation of elliptic integral to my implementation
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lucas Ruela
am 28 Mär. 2024
Kommentiert: Lucas Ruela
am 28 Mär. 2024
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 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Special Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!