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

7 次查看(过去 30 天)
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?

采纳的回答

Torsten
Torsten 2024-3-28,16:16
移动:Torsten 2024-3-28,16:18
You have to supply k^2, not k:
ellipke(0.25)
ans = 1.6858

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Special Functions 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by