Hi.
I do not know is this known, there was a recent thread about calculating perimeter of ellipses and elliptic integrals of first and second kind. There was presented an iteration with modified agm formula, but no reasoning why it worked.
In general refer to http://en.wikipedia.org/wiki/Elliptic_integral
Which states that elliptic integrals of 1st kind K(k) can most efficiently be computed in terms of the arithmetic-geometric mean:
K(k)=(pi/2)/agm(1-k, 1+k) (1)
For elliptic integrals of 1st and 2nd kind we have following relationship
dK(k) /dk = E(k)/(k(1-k^2)) – K(k)/k (2)
which can be re-arranged into
E(k)=k(1-k*k) dK(k)/dk + (1-k*k) K(k) (3)
Now take a second look on the agm,
K(zk)=(pi/2)/agm(1-zk, 1+zk) (4)
and allow zk be complex and define such iteration to define complex K.
This is useful because if we remember what Valentine taught us about numeric derivation a while ago: numeric derivation rule, let dk be in complex plane instead of real , we then have two advantages, we can “freely” choose the step dk without numerical problems and compute derivate for real values of k using s side-step in imaginary plane:
dK(k)/dk = im(K(k,dk))/ dk (5)
thus E(k) can be computed directly by computing K(zk) and dK(zk) with complex agm .
Further, provided dk is small enough, to avoid “interference” between real and imaginary values by choosing a suitable value for dk, say for the calculator use dk= (0, 1E-12) then
you can compute both dK(k)/dk and K(k) in same complex agm iteration.
thus if we want to calculate E(k) we use initial values
k0=k+i1E-12
A0=1-k0
B0=1+k0
A0 = (1-k, -1E-12)
B0 = (1+k, 1E-12)
Do complex AGM
{ Ai= (A0+B0)/2; Bi=SQRT(A*B) }
until Ai==Bi then
Zn=0.5*pi/An
K(k)= REAL(Zn)
dK(k)/dk= IM(Zn)/1E-12
E(k)= k(1-k^2) dK(k)/dk + (1-k^2) K(k)
In user rpl
AGMc << 1. 12. START DUP 2 + 2 / UNROT * SQRT NEXT DROP >>
Kdk = << 1E-12 DUP2 R->C -> k dk z << 1 z – 1 z + AGMc pi 2. / SWAP / C->R dk / >> >>
Ek = << -> k << k Kdk 1. k k * - DUP UNROT k * * UNROT * + >> >>
Notice the almost one-liner programs!
This can be made even more efficient considering that we in principle could use extended (infinite) precision with small dk. Since what we actually want to do is keep the real and imaginary values separately and we are free to choose dk as we like so we can split and simplify (de-complexify) as shown in part 2.
Any comments are welcome
Best regards
Gjermund