std::legendre, std::legendref, std::legendrel
来自cppreference.com
< cpp | numeric | special functions
在标头 <cmath> 定义 | ||
(1) | ||
float legendre (unsignedint n, float x ); double legendre (unsignedint n, double x ); | (C++17 起) (C++23 前) | |
/* 浮点数类型 */ legendre(unsignedint n, /* 浮点数类型 */ x ); | (C++23 起) | |
float legendref(unsignedint n, float x ); | (2) | (C++17 起) |
longdouble legendrel(unsignedint n, longdouble x ); | (3) | (C++17 起) |
在标头 <cmath> 定义 | ||
template<class Integer > double legendre (unsignedint n, Integer x ); | (A) | (C++17 起) |
A) 为所有整数类型提供额外重载,将它们当做 double。
目录 |
[编辑]参数
n | - | 多项式的次数 |
x | - | 实参,浮点数或整数 |
[编辑]返回值
如果没有发生错误,那么返回 x 的 n 阶非关联勒让德多项式的值,即1 |
2n n! |
dn |
dxn |
-1)n
。
[编辑]错误处理
可能报告 math_errhandling 中指定的错误
- 如果实参是 NaN,那么返回 NaN 且不报告定义域错误
- 不要求函数对 |x|>1 有定义
- 如果 n 大于或等于 128,那么行为由实现定义
[编辑]注解
不支持 C++17,但支持 ISO 29124:2010 的实现在定义了 __STDCPP_MATH_SPEC_FUNCS__
为至少 201003L 的值,且用户在包含任何标准库头文件前定义了 __STDCPP_WANT_MATH_SPEC_FUNCS__
时也会提供此函数。
不支持 ISO 29124:2010 但支持 TR 19768:2007 (TR1) 的实现也会在标头 tr1/cmath
及命名空间 std::tr1
中提供此函数。
此函数的一种实现参考 boost.math。
前几个勒让德多项式是:
函数 | 多项式 | ||
---|---|---|---|
legendre(0, x) | 1 | ||
legendre(1, x) | x | ||
legendre(2, x) |
- 1) | ||
legendre(3, x) |
- 3x) | ||
legendre(4, x) |
- 30x2 + 3) |
额外重载不需要严格以 (A) 的形式提供。它们只需要能够对它们的整数类型实参 num 确保 std::legendre(int_num, num) 和 std::legendre(int_num, static_cast<double>(num)) 的效果相同即可。
[编辑]示例
运行此代码
输出:
-0.335938=-0.335938 0.157715=0.157715
[编辑]参阅
(C++17)(C++17)(C++17) | 拉盖尔多项式 (函数) |
(C++17)(C++17)(C++17) | 埃尔米特多项式 (函数) |
[编辑]外部链接
Weisstein, Eric W. “勒让德多项式”来自 MathWorld--A Wolfram Web Resource。 |