std::assoc_legendre, std::assoc_legendref, std::assoc_legendrel
来自cppreference.com
< cpp | experimental | special functions
double assoc_legendre( unsigned int n, unsigned int m, double x ); double assoc_legendre( unsigned int n, unsigned int m, float x ); |
(1) | |
double assoc_legendre( unsigned int n, unsigned int m, IntegralType x ); |
(2) | |
Template:cpp/experimental/special math/macro note
参数
n | - | 多项式的度数,无符号整数类型的值 |
m | - | 多项式的阶数,无符号整数类型的值 |
x | - | 实参,浮点或整数类型的值 |
返回值
如果未发生错误,则返回 x 的连带勒让德多项式的值,即 (1 - x2)m/2
dm |
dxm |
n(x)(其中 P
n(x) 为非连带勒让德多项式,std::legendre(n, x))。
错误处理
根据 math_errhandling 的规定进行错误报告。
- 如果实参为 NaN,则返回 NaN 但不报告定义域错误。
- 如果 |x| > 1,则发生定义域错误。
- 如果
n
大于或等于 128,则其行为由实现定义。
注解
不支持 TR 29124 但支持 TR 19768 的实现,在头文件 tr1/cmath
和命名空间 std::tr1
中提供此函
此函数的实现也在 boost.math 中可用。
前几个连带勒让德多项式:
- assoc_legendre(0, 0, x) = 1。
- assoc_legendre(1, 0, x) = x。
- assoc_legendre(1, 1, x) = -(1 - x2
)1/2
。 - assoc_legendre(2, 0, x) =
(3x21 2
- 1)。 - assoc_legendre(2, 1, x) = -3x(1 - x2
)1/2
。 - assoc_legendre(2, 2, x) = 3(1 - x2
)。
示例
(works as shown with gcc 6.0)
运行此代码
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1 #include <cmath> #include <iostream> double P20(double x) { return 0.5 * (3 * x * x - 1); } double P21(double x) { return -3.0 * x * std::sqrt(1 - x * x); } double P22(double x) { return 3 * (1 - x * x); } int main() { // spot-checks std::cout << std::assoc_legendre(2, 0, 0.5) << '=' << P20(0.5) << '\n' << std::assoc_legendre(2, 1, 0.5) << '=' << P21(0.5) << '\n' << std::assoc_legendre(2, 2, 0.5) << '=' << P22(0.5) << '\n'; }
输出:
-0.125=-0.125 -1.29904=-1.29904 2.25=2.25
参阅
勒让德多项式 (函数) |
外部链接
Weisstein, Eric W. "Associated Legendre Polynomial." From MathWorld--A Wolfram Web Resource.