]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // (C) Copyright John Maddock 2006. | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | #ifndef BOOST_MATH_SPECIAL_HERMITE_HPP | |
8 | #define BOOST_MATH_SPECIAL_HERMITE_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/tools/config.hpp> | |
16 | #include <boost/math/policies/error_handling.hpp> | |
17 | ||
18 | namespace boost{ | |
19 | namespace math{ | |
20 | ||
f67539c2 | 21 | // Recurrence relation for Hermite polynomials: |
7c673cae FG |
22 | template <class T1, class T2, class T3> |
23 | inline typename tools::promote_args<T1, T2, T3>::type | |
24 | hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1) | |
25 | { | |
26 | return (2 * x * Hn - 2 * n * Hnm1); | |
27 | } | |
28 | ||
29 | namespace detail{ | |
30 | ||
f67539c2 | 31 | // Implement Hermite polynomials via recurrence: |
7c673cae FG |
32 | template <class T> |
33 | T hermite_imp(unsigned n, T x) | |
34 | { | |
35 | T p0 = 1; | |
36 | T p1 = 2 * x; | |
37 | ||
38 | if(n == 0) | |
39 | return p0; | |
40 | ||
41 | unsigned c = 1; | |
42 | ||
43 | while(c < n) | |
44 | { | |
45 | std::swap(p0, p1); | |
46 | p1 = hermite_next(c, x, p0, p1); | |
47 | ++c; | |
48 | } | |
49 | return p1; | |
50 | } | |
51 | ||
52 | } // namespace detail | |
53 | ||
54 | template <class T, class Policy> | |
55 | inline typename tools::promote_args<T>::type | |
56 | hermite(unsigned n, T x, const Policy&) | |
57 | { | |
58 | typedef typename tools::promote_args<T>::type result_type; | |
59 | typedef typename policies::evaluation<result_type, Policy>::type value_type; | |
60 | return policies::checked_narrowing_cast<result_type, Policy>(detail::hermite_imp(n, static_cast<value_type>(x)), "boost::math::hermite<%1%>(unsigned, %1%)"); | |
61 | } | |
62 | ||
63 | template <class T> | |
64 | inline typename tools::promote_args<T>::type | |
65 | hermite(unsigned n, T x) | |
66 | { | |
67 | return boost::math::hermite(n, x, policies::policy<>()); | |
68 | } | |
69 | ||
70 | } // namespace math | |
71 | } // namespace boost | |
72 | ||
73 | #endif // BOOST_MATH_SPECIAL_HERMITE_HPP | |
74 | ||
75 | ||
76 |