mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [
git repo
]
Loading...
Searching...
No Matches
legendre.hpp
Go to the documentation of this file.
1
/** \file legendre.hpp
2
* \brief Declares and defines Legendre polynomials.
3
* \ingroup gen_math_files
4
* \author Jared R. Males (jaredmales@gmail.com)
5
*
6
*/
7
8
//***********************************************************************//
9
// Copyright 2021 Jared R. Males (jaredmales@gmail.com)
10
//
11
// This file is part of mxlib.
12
//
13
// mxlib is free software: you can redistribute it and/or modify
14
// it under the terms of the GNU General Public License as published by
15
// the Free Software Foundation, either version 3 of the License, or
16
// (at your option) any later version.
17
//
18
// mxlib is distributed in the hope that it will be useful,
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
// GNU General Public License for more details.
22
//
23
// You should have received a copy of the GNU General Public License
24
// along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25
//***********************************************************************//
26
27
#ifndef mx_legendre_hpp
28
#define mx_legendre_hpp
29
30
#include <type_traits>
31
32
#ifdef MX_INCLUDE_BOOST
33
#include <boost/math/special_functions/legendre.hpp>
34
#endif
35
36
namespace
mx
37
{
38
namespace
math
39
{
40
namespace
func
41
{
42
43
/// Legendre Polynomials
44
/** See https://en.wikipedia.org/wiki/Legendre_polynomials
45
* and https://www.boost.org/doc/libs/1_75_0/libs/math/doc/html/math_toolkit/sf_poly/legendre.html
46
*
47
* \returns the value of the n-th Legendre polynomial at x.
48
*
49
* \ingroup functions
50
*/
51
template
<
typename
T>
52
T
legendre_p
(
int
n,
///< [in] the order of the Legendre polynomial, n>=0.
53
T x
///< [in] the argument, -1 <= x <= 1.
54
)
55
{
56
#ifdef MX_INCLUDE_BOOST
57
return
boost::math::legendre_p<T>( n, x );
58
#else
59
static_assert
(
60
std::is_fundamental<T>::value || !std::is_fundamental<T>::value,
61
"legendre_p<T> not specialized for type T, and MX_INCLUDE_BOOST is not defined, so I can't just use boost."
);
62
return
0;
63
#endif
64
}
65
66
template
<>
67
float
legendre_p<float>(
int
n,
float
x );
68
69
template
<>
70
double
legendre_p<double>(
int
n,
double
x );
71
72
template
<>
73
long
double
legendre_p<long double>(
int
n,
long
double
x );
74
75
#ifdef HASQUAD
76
template
<>
77
__float128
legendre_p<__float128>
(
int
n, __float128 x );
78
#endif
79
80
/// The orthonormal Legendre polynomials
81
/** A version of the Legendre polynomials which are orthonormal on the interval
82
* -1 <= x <= 1.
83
*
84
* \returns the value of the n-th orthonormal Legendre polynomial at x.
85
*/
86
template
<
typename
T>
87
T
orthoNormalLegendre
(
int
n, T x )
88
{
89
return
sqrt( (
static_cast<
T
>
( 2 * n + 1 ) ) /
static_cast<
T
>
( 2 ) ) *
legendre_p<T>
( n, x );
90
}
91
92
}
// namespace func
93
}
// namespace math
94
}
// namespace mx
95
96
#endif
// mx_legendre_hpp
mx::math::func::legendre_p
T legendre_p(int n, T x)
Legendre Polynomials.
Definition
legendre.hpp:52
mx::math::func::orthoNormalLegendre
T orthoNormalLegendre(int n, T x)
The orthonormal Legendre polynomials.
Definition
legendre.hpp:87
mx
The mxlib c++ namespace.
Definition
mxlib.hpp:37
math
func
legendre.hpp
Generated on
for mxlib by
1.15.0