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

5 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Torsten
Torsten am 28 Mär. 2024
Verschoben: Torsten am 28 Mär. 2024
You have to supply k^2, not k:
ellipke(0.25)
ans = 1.6858

Weitere Antworten (0)

Kategorien

Mehr zu Special Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by