heuman_lambda.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (c) 2015 John Maddock
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_ELLINT_HL_HPP
  6. #define BOOST_MATH_ELLINT_HL_HPP
  7. #ifdef _MSC_VER
  8. #pragma once
  9. #endif
  10. #include <boost/math/special_functions/math_fwd.hpp>
  11. #include <boost/math/special_functions/ellint_rj.hpp>
  12. #include <boost/math/special_functions/ellint_rj.hpp>
  13. #include <boost/math/special_functions/ellint_1.hpp>
  14. #include <boost/math/special_functions/jacobi_zeta.hpp>
  15. #include <boost/math/constants/constants.hpp>
  16. #include <boost/math/policies/error_handling.hpp>
  17. #include <boost/math/tools/workaround.hpp>
  18. // Elliptic integral the Jacobi Zeta function.
  19. namespace boost { namespace math {
  20. namespace detail{
  21. // Elliptic integral - Jacobi Zeta
  22. template <typename T, typename Policy>
  23. T heuman_lambda_imp(T phi, T k, const Policy& pol)
  24. {
  25. BOOST_MATH_STD_USING
  26. using namespace boost::math::tools;
  27. using namespace boost::math::constants;
  28. const char* function = "boost::math::heuman_lambda<%1%>(%1%, %1%)";
  29. if(fabs(k) > 1)
  30. return policies::raise_domain_error<T>(function, "We require |k| <= 1 but got k = %1%", k, pol);
  31. T result;
  32. T sinp = sin(phi);
  33. T cosp = cos(phi);
  34. T s2 = sinp * sinp;
  35. T k2 = k * k;
  36. T kp = 1 - k2;
  37. T delta = sqrt(1 - (kp * s2));
  38. if(fabs(phi) <= constants::half_pi<T>())
  39. {
  40. result = kp * sinp * cosp / (delta * constants::half_pi<T>());
  41. result *= ellint_rf_imp(T(0), kp, T(1), pol) + k2 * ellint_rj(T(0), kp, T(1), T(1 - k2 / (delta * delta)), pol) / (3 * delta * delta);
  42. }
  43. else
  44. {
  45. T rkp = sqrt(kp);
  46. T ratio;
  47. if(rkp == 1)
  48. {
  49. return policies::raise_domain_error<T>(function, "When 1-k^2 == 1 then phi must be < Pi/2, but got phi = %1%", phi, pol);
  50. }
  51. else
  52. ratio = ellint_f_imp(phi, rkp, pol) / ellint_k_imp(rkp, pol);
  53. result = ratio + ellint_k_imp(k, pol) * jacobi_zeta_imp(phi, rkp, pol) / constants::half_pi<T>();
  54. }
  55. return result;
  56. }
  57. } // detail
  58. template <class T1, class T2, class Policy>
  59. inline typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi, const Policy& pol)
  60. {
  61. typedef typename tools::promote_args<T1, T2>::type result_type;
  62. typedef typename policies::evaluation<result_type, Policy>::type value_type;
  63. return policies::checked_narrowing_cast<result_type, Policy>(detail::heuman_lambda_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::heuman_lambda<%1%>(%1%,%1%)");
  64. }
  65. template <class T1, class T2>
  66. inline typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi)
  67. {
  68. return boost::math::heuman_lambda(k, phi, policies::policy<>());
  69. }
  70. }} // namespaces
  71. #endif // BOOST_MATH_ELLINT_D_HPP