/// Complete elliptic integrals of the second kind. double comp_ellint_2(double k) { const gsl_mode_t mode = GSL_PREC_DOUBLE; gsl_sf_result result; int stat = gsl_sf_ellint_Ecomp_e(k, mode, &result); if (stat != GSL_SUCCESS) { std::ostringstream msg("Error in ellint_2:"); msg << " k=" << k; throw std::runtime_error(msg.str()); } else return result.val; }
/* [Carlson, Numer. Math. 33 (1979) 1, (4.2)] */ int gsl_sf_ellint_E_e(double phi, double k, gsl_mode_t mode, gsl_sf_result * result) { const double sin_phi = sin(phi); const double sin2_phi = sin_phi * sin_phi; const double x = 1.0 - sin2_phi; const double y = 1.0 - k*k*sin2_phi; if(x < GSL_DBL_EPSILON) { return gsl_sf_ellint_Ecomp_e(k, mode, result); } else { gsl_sf_result rf; gsl_sf_result rd; const double sin3_phi = sin2_phi * sin_phi; const int rfstatus = gsl_sf_ellint_RF_e(x, y, 1.0, mode, &rf); const int rdstatus = gsl_sf_ellint_RD_e(x, y, 1.0, mode, &rd); result->val = sin_phi * rf.val - k*k/3.0 * sin3_phi * rd.val; result->err = GSL_DBL_EPSILON * fabs(sin_phi * rf.val); result->err += fabs(sin_phi*rf.err); result->err += k*k/3.0 * GSL_DBL_EPSILON * fabs(sin3_phi * rd.val); result->err += k*k/3.0 * fabs(sin3_phi*rd.err); return GSL_ERROR_SELECT_2(rfstatus, rdstatus); } }
double gsl_sf_ellint_Ecomp(double k, gsl_mode_t mode) { EVAL_RESULT(gsl_sf_ellint_Ecomp_e(k, mode, &result)); }
/** * C++ version of gsl_sf_ellint_Ecomp_e(). * Legendre form of complete elliptic integrals * * E(k) = Integral[ Sqrt[1 - k^2 Sin[t]^2], {t, 0, Pi/2}] * * @param k A real number * @param mode The mode * @param result The result as a @c gsl::sf::result object * @return GSL_SUCCESS or GSL_EDOM */ inline int Ecomp_e( double k, mode_t mode, result& result ){ return gsl_sf_ellint_Ecomp_e( k, mode, &result ); }