std::legendre, std::legendref, std::legendrel
来自cppreference.com
< cpp | experimental | special functions
double legendre( unsigned int n, double x ); double legendre( unsigned int n, float x ); |
(1) | |
double legendre( unsigned int n, IntegralType x ); |
(2) | |
与所有特殊函数一样,仅当实现将 __STDCPP_MATH_SPEC_FUNCS__
定义为至少 201003L 的值,且用户在包含任何标准库头文件前定义了 __STDCPP_WANT_MATH_SPEC_FUNCS__
时,legendre
才保证在 <cmath>
中可用。
参数
n | - | 多项式的度数 |
x | - | 实参,浮点或整数类型的值 |
返回值
如果未发生错误,则返回 x 的n
阶无连带勒让德多项式的值,即 1 |
2n n! |
dn |
dxn |
- 1)n
。
错误处理
根据 math_errhandling 的规定进行错误报告。
- 如果实参为 NaN,则返回 NaN 但不报告定义域错误。
- 对于 |x| > 1,不要求函数有定义。
- 如果 n 大于或等于 128,则其行为由实现定义。
注解
不支持 TR 29124 但支持 TR 19768 的实现,在头文件 tr1/cmath
和命名空间 std::tr1
中提供此函数。
此函数的实现也在 boost.math 中可用。
前几个勒让德多项式为:
- legendre(0, x) = 1。
- legendre(1, x) = x。
- legendre(2, x) =
(3x21 2
- 1)。 - legendre(3, x) =
(5x31 2
- 3x)。 - legendre(4, x) =
(35x41 8
- 30x2
+ 3)。
示例
(以 gcc 6.0 运行)
运行此代码
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1 #include <cmath> #include <iostream> double P3(double x) { return 0.5 * (5 * std::pow(x, 3) - 3 * x); } double P4(double x) { return 0.125 * (35 * std::pow(x, 4) - 30 * x * x + 3); } int main() { // spot-checks std::cout << std::legendre(3, 0.25) << '=' << P3(0.25) << '\n' << std::legendre(4, 0.25) << '=' << P4(0.25) << '\n'; }
输出:
-0.335938=-0.335938 0.157715=0.157715
参阅
拉盖尔多项式 (函数) | |
埃尔米特多项式 (函数) |
外部链接
Weisstein, Eric W. "Legendre Polynomial." From MathWorld — A Wolfram Web Resource. |