]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | // | |
6 | ||
7 | #ifndef BOOST_MATH_ELLINT_JZ_HPP | |
8 | #define BOOST_MATH_ELLINT_JZ_HPP | |
9 | ||
10 | #ifdef _MSC_VER | |
11 | #pragma once | |
12 | #endif | |
13 | ||
14 | #include <boost/math/special_functions/math_fwd.hpp> | |
15 | #include <boost/math/special_functions/ellint_1.hpp> | |
16 | #include <boost/math/special_functions/ellint_rj.hpp> | |
1e59de90 | 17 | #include <boost/math/special_functions/sign.hpp> |
7c673cae FG |
18 | #include <boost/math/constants/constants.hpp> |
19 | #include <boost/math/policies/error_handling.hpp> | |
20 | #include <boost/math/tools/workaround.hpp> | |
21 | ||
22 | // Elliptic integral the Jacobi Zeta function. | |
23 | ||
24 | namespace boost { namespace math { | |
25 | ||
26 | namespace detail{ | |
27 | ||
28 | // Elliptic integral - Jacobi Zeta | |
29 | template <typename T, typename Policy> | |
30 | T jacobi_zeta_imp(T phi, T k, const Policy& pol) | |
31 | { | |
32 | BOOST_MATH_STD_USING | |
33 | using namespace boost::math::tools; | |
34 | using namespace boost::math::constants; | |
35 | ||
36 | bool invert = false; | |
37 | if(phi < 0) | |
38 | { | |
39 | phi = fabs(phi); | |
40 | invert = true; | |
41 | } | |
42 | ||
43 | T result; | |
44 | T sinp = sin(phi); | |
45 | T cosp = cos(phi); | |
46 | T s2 = sinp * sinp; | |
47 | T k2 = k * k; | |
48 | T kp = 1 - k2; | |
49 | if(k == 1) | |
50 | result = sinp * (boost::math::sign)(cosp); // We get here by simplifying JacobiZeta[w, 1] in Mathematica, and the fact that 0 <= phi. | |
51 | else | |
52 | 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)); | |
53 | return invert ? T(-result) : result; | |
54 | } | |
55 | ||
56 | } // detail | |
57 | ||
58 | template <class T1, class T2, class Policy> | |
59 | inline typename tools::promote_args<T1, T2>::type jacobi_zeta(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::jacobi_zeta_imp(static_cast<value_type>(phi), static_cast<value_type>(k), pol), "boost::math::jacobi_zeta<%1%>(%1%,%1%)"); | |
64 | } | |
65 | ||
66 | template <class T1, class T2> | |
67 | inline typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi) | |
68 | { | |
69 | return boost::math::jacobi_zeta(k, phi, policies::policy<>()); | |
70 | } | |
71 | ||
72 | }} // namespaces | |
73 | ||
74 | #endif // BOOST_MATH_ELLINT_D_HPP | |
75 |