/// <summary> /// Returns the complete elliptic integral of the second kind E(k) = E(π/2,k) /// <para>E(k) = ∫ sqrt(1-k^2*sin^2(θ)) dθ, θ={0,π/2}</para> /// </summary> /// <param name="k">The modulus. Requires |k| ≤ 1</param> public static double EllintE(double k) { if (!(k >= -1 && k <= 1)) { Policies.ReportDomainError("EllintE(k: {0}): Requires |k| <= 1", k); return(double.NaN); } // Small series at k == 0 // Note that z = k^2 in the following link // http://functions.wolfram.com/EllipticIntegrals/EllipticE/06/01/03/01/0004/ double k2 = k * k; if (k2 < DoubleLimits.RootMachineEpsilon._13) { if (k2 < 4 * DoubleLimits.MachineEpsilon) { return(Math.PI / 2); // E(0) = Pi/2 } return((Math.PI / 2) * HypergeometricSeries.Sum2F1(-0.5, 0.5, 1, k2)); } if (Math.Abs(k) == 1) { return(1); } double x = 0; double y = 1 - k2; double z = 1; double value = 2 * Math2.EllintRG(x, y, z); return(value); }