Chris@102
|
1 // Copyright (c) 2015 John Maddock
|
Chris@102
|
2 // Use, modification and distribution are subject to the
|
Chris@102
|
3 // Boost Software License, Version 1.0. (See accompanying file
|
Chris@102
|
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
5 //
|
Chris@102
|
6
|
Chris@102
|
7 #ifndef BOOST_MATH_ELLINT_JZ_HPP
|
Chris@102
|
8 #define BOOST_MATH_ELLINT_JZ_HPP
|
Chris@102
|
9
|
Chris@102
|
10 #ifdef _MSC_VER
|
Chris@102
|
11 #pragma once
|
Chris@102
|
12 #endif
|
Chris@102
|
13
|
Chris@102
|
14 #include <boost/math/special_functions/math_fwd.hpp>
|
Chris@102
|
15 #include <boost/math/special_functions/ellint_1.hpp>
|
Chris@102
|
16 #include <boost/math/special_functions/ellint_rj.hpp>
|
Chris@102
|
17 #include <boost/math/constants/constants.hpp>
|
Chris@102
|
18 #include <boost/math/policies/error_handling.hpp>
|
Chris@102
|
19 #include <boost/math/tools/workaround.hpp>
|
Chris@102
|
20
|
Chris@102
|
21 // Elliptic integral the Jacobi Zeta function.
|
Chris@102
|
22
|
Chris@102
|
23 namespace boost { namespace math {
|
Chris@102
|
24
|
Chris@102
|
25 namespace detail{
|
Chris@102
|
26
|
Chris@102
|
27 // Elliptic integral - Jacobi Zeta
|
Chris@102
|
28 template <typename T, typename Policy>
|
Chris@102
|
29 T jacobi_zeta_imp(T phi, T k, const Policy& pol)
|
Chris@102
|
30 {
|
Chris@102
|
31 BOOST_MATH_STD_USING
|
Chris@102
|
32 using namespace boost::math::tools;
|
Chris@102
|
33 using namespace boost::math::constants;
|
Chris@102
|
34
|
Chris@102
|
35 bool invert = false;
|
Chris@102
|
36 if(phi < 0)
|
Chris@102
|
37 {
|
Chris@102
|
38 phi = fabs(phi);
|
Chris@102
|
39 invert = true;
|
Chris@102
|
40 }
|
Chris@102
|
41
|
Chris@102
|
42 T result;
|
Chris@102
|
43 T sinp = sin(phi);
|
Chris@102
|
44 T cosp = cos(phi);
|
Chris@102
|
45 T s2 = sinp * sinp;
|
Chris@102
|
46 T k2 = k * k;
|
Chris@102
|
47 T kp = 1 - k2;
|
Chris@102
|
48 if(k == 1)
|
Chris@102
|
49 result = sinp * (boost::math::sign)(cosp); // We get here by simplifying JacobiZeta[w, 1] in Mathematica, and the fact that 0 <= phi.
|
Chris@102
|
50 else
|
Chris@102
|
51 result = k2 * sinp * cosp * sqrt(1 - k2 * s2) * ellint_rj_imp(T(0), kp, T(1), T(1 - k2 * s2), pol) / (3 * ellint_k_imp(k, pol));
|
Chris@102
|
52 return invert ? T(-result) : result;
|
Chris@102
|
53 }
|
Chris@102
|
54
|
Chris@102
|
55 } // detail
|
Chris@102
|
56
|
Chris@102
|
57 template <class T1, class T2, class Policy>
|
Chris@102
|
58 inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi, const Policy& pol)
|
Chris@102
|
59 {
|
Chris@102
|
60 typedef typename tools::promote_args<T1, T2>::type result_type;
|
Chris@102
|
61 typedef typename policies::evaluation<result_type, Policy>::type value_type;
|
Chris@102
|
62 return policies::checked_narrowing_cast<result_type, Policy>(detail::jacobi_zeta_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::jacobi_zeta<%1%>(%1%,%1%)");
|
Chris@102
|
63 }
|
Chris@102
|
64
|
Chris@102
|
65 template <class T1, class T2>
|
Chris@102
|
66 inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi)
|
Chris@102
|
67 {
|
Chris@102
|
68 return boost::math::jacobi_zeta(k, phi, policies::policy<>());
|
Chris@102
|
69 }
|
Chris@102
|
70
|
Chris@102
|
71 }} // namespaces
|
Chris@102
|
72
|
Chris@102
|
73 #endif // BOOST_MATH_ELLINT_D_HPP
|
Chris@102
|
74
|