Chris@16
|
1
|
Chris@16
|
2 // (C) Copyright John Maddock 2006.
|
Chris@16
|
3 // Use, modification and distribution are subject to the
|
Chris@16
|
4 // Boost Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 #ifndef BOOST_MATH_SPECIAL_LAGUERRE_HPP
|
Chris@16
|
8 #define BOOST_MATH_SPECIAL_LAGUERRE_HPP
|
Chris@16
|
9
|
Chris@16
|
10 #ifdef _MSC_VER
|
Chris@16
|
11 #pragma once
|
Chris@16
|
12 #endif
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/math/special_functions/math_fwd.hpp>
|
Chris@16
|
15 #include <boost/math/tools/config.hpp>
|
Chris@16
|
16 #include <boost/math/policies/error_handling.hpp>
|
Chris@16
|
17
|
Chris@16
|
18 namespace boost{
|
Chris@16
|
19 namespace math{
|
Chris@16
|
20
|
Chris@16
|
21 // Recurrance relation for Laguerre polynomials:
|
Chris@16
|
22 template <class T1, class T2, class T3>
|
Chris@16
|
23 inline typename tools::promote_args<T1, T2, T3>::type
|
Chris@16
|
24 laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1)
|
Chris@16
|
25 {
|
Chris@16
|
26 typedef typename tools::promote_args<T1, T2, T3>::type result_type;
|
Chris@16
|
27 return ((2 * n + 1 - result_type(x)) * result_type(Ln) - n * result_type(Lnm1)) / (n + 1);
|
Chris@16
|
28 }
|
Chris@16
|
29
|
Chris@16
|
30 namespace detail{
|
Chris@16
|
31
|
Chris@16
|
32 // Implement Laguerre polynomials via recurrance:
|
Chris@16
|
33 template <class T>
|
Chris@16
|
34 T laguerre_imp(unsigned n, T x)
|
Chris@16
|
35 {
|
Chris@16
|
36 T p0 = 1;
|
Chris@16
|
37 T p1 = 1 - x;
|
Chris@16
|
38
|
Chris@16
|
39 if(n == 0)
|
Chris@16
|
40 return p0;
|
Chris@16
|
41
|
Chris@16
|
42 unsigned c = 1;
|
Chris@16
|
43
|
Chris@16
|
44 while(c < n)
|
Chris@16
|
45 {
|
Chris@16
|
46 std::swap(p0, p1);
|
Chris@16
|
47 p1 = laguerre_next(c, x, p0, p1);
|
Chris@16
|
48 ++c;
|
Chris@16
|
49 }
|
Chris@16
|
50 return p1;
|
Chris@16
|
51 }
|
Chris@16
|
52
|
Chris@16
|
53 template <class T, class Policy>
|
Chris@16
|
54 inline typename tools::promote_args<T>::type
|
Chris@16
|
55 laguerre(unsigned n, T x, const Policy&, const mpl::true_&)
|
Chris@16
|
56 {
|
Chris@16
|
57 typedef typename tools::promote_args<T>::type result_type;
|
Chris@16
|
58 typedef typename policies::evaluation<result_type, Policy>::type value_type;
|
Chris@16
|
59 return policies::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, static_cast<value_type>(x)), "boost::math::laguerre<%1%>(unsigned, %1%)");
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@16
|
62 template <class T>
|
Chris@16
|
63 inline typename tools::promote_args<T>::type
|
Chris@16
|
64 laguerre(unsigned n, unsigned m, T x, const mpl::false_&)
|
Chris@16
|
65 {
|
Chris@16
|
66 return boost::math::laguerre(n, m, x, policies::policy<>());
|
Chris@16
|
67 }
|
Chris@16
|
68
|
Chris@16
|
69 } // namespace detail
|
Chris@16
|
70
|
Chris@16
|
71 template <class T>
|
Chris@16
|
72 inline typename tools::promote_args<T>::type
|
Chris@16
|
73 laguerre(unsigned n, T x)
|
Chris@16
|
74 {
|
Chris@16
|
75 return laguerre(n, x, policies::policy<>());
|
Chris@16
|
76 }
|
Chris@16
|
77
|
Chris@16
|
78 // Recurrence for associated polynomials:
|
Chris@16
|
79 template <class T1, class T2, class T3>
|
Chris@16
|
80 inline typename tools::promote_args<T1, T2, T3>::type
|
Chris@16
|
81 laguerre_next(unsigned n, unsigned l, T1 x, T2 Pl, T3 Plm1)
|
Chris@16
|
82 {
|
Chris@16
|
83 typedef typename tools::promote_args<T1, T2, T3>::type result_type;
|
Chris@16
|
84 return ((2 * n + l + 1 - result_type(x)) * result_type(Pl) - (n + l) * result_type(Plm1)) / (n+1);
|
Chris@16
|
85 }
|
Chris@16
|
86
|
Chris@16
|
87 namespace detail{
|
Chris@16
|
88 // Laguerre Associated Polynomial:
|
Chris@16
|
89 template <class T, class Policy>
|
Chris@16
|
90 T laguerre_imp(unsigned n, unsigned m, T x, const Policy& pol)
|
Chris@16
|
91 {
|
Chris@16
|
92 // Special cases:
|
Chris@16
|
93 if(m == 0)
|
Chris@16
|
94 return boost::math::laguerre(n, x, pol);
|
Chris@16
|
95
|
Chris@16
|
96 T p0 = 1;
|
Chris@16
|
97
|
Chris@16
|
98 if(n == 0)
|
Chris@16
|
99 return p0;
|
Chris@16
|
100
|
Chris@16
|
101 T p1 = m + 1 - x;
|
Chris@16
|
102
|
Chris@16
|
103 unsigned c = 1;
|
Chris@16
|
104
|
Chris@16
|
105 while(c < n)
|
Chris@16
|
106 {
|
Chris@16
|
107 std::swap(p0, p1);
|
Chris@16
|
108 p1 = laguerre_next(c, m, x, p0, p1);
|
Chris@16
|
109 ++c;
|
Chris@16
|
110 }
|
Chris@16
|
111 return p1;
|
Chris@16
|
112 }
|
Chris@16
|
113
|
Chris@16
|
114 }
|
Chris@16
|
115
|
Chris@16
|
116 template <class T, class Policy>
|
Chris@16
|
117 inline typename tools::promote_args<T>::type
|
Chris@16
|
118 laguerre(unsigned n, unsigned m, T x, const Policy& pol)
|
Chris@16
|
119 {
|
Chris@16
|
120 typedef typename tools::promote_args<T>::type result_type;
|
Chris@16
|
121 typedef typename policies::evaluation<result_type, Policy>::type value_type;
|
Chris@16
|
122 return policies::checked_narrowing_cast<result_type, Policy>(detail::laguerre_imp(n, m, static_cast<value_type>(x), pol), "boost::math::laguerre<%1%>(unsigned, unsigned, %1%)");
|
Chris@16
|
123 }
|
Chris@16
|
124
|
Chris@16
|
125 template <class T1, class T2>
|
Chris@16
|
126 inline typename laguerre_result<T1, T2>::type
|
Chris@16
|
127 laguerre(unsigned n, T1 m, T2 x)
|
Chris@16
|
128 {
|
Chris@16
|
129 typedef typename policies::is_policy<T2>::type tag_type;
|
Chris@16
|
130 return detail::laguerre(n, m, x, tag_type());
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 } // namespace math
|
Chris@16
|
134 } // namespace boost
|
Chris@16
|
135
|
Chris@16
|
136 #endif // BOOST_MATH_SPECIAL_LAGUERRE_HPP
|
Chris@16
|
137
|
Chris@16
|
138
|
Chris@16
|
139
|