std:: legendre, std:: legendref, std:: legendrel
|
定义于头文件
<cmath>
|
||
| (1) | ||
|
float
legendre
(
unsigned
int
n,
float
x
)
;
double
legendre
(
unsigned
int
n,
double
x
)
;
|
(C++17 起)
(C++23 前) |
|
|
/* floating-point-type */
legendre
(
unsigned
int
n,
/* floating-point-type */ x ) ; |
(C++23 起) | |
|
float
legendref
(
unsigned
int
n,
float
x
)
;
|
(2) | (C++17 起) |
|
long
double
legendrel
(
unsigned
int
n,
long
double
x
)
;
|
(3) | (C++17 起) |
|
定义于头文件
<cmath>
|
||
|
template
<
class
Integer
>
double legendre ( unsigned int n, Integer x ) ; |
(A) | (C++17 起) |
目录 |
参数
| n | - | 多项式的次数 |
| x | - | 参数,浮点数或整数值 |
返回值
If no errors occur, value of the order- n unassociated Legendre polynomial of x , that is| 1 |
|
2
n
n! |
|
d
n
|
|
dx
n
|
-1) n
, is returned.
错误处理
错误报告方式可按照 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 ) |
- 30x 2 + 3) |
额外的重载不需要完全按照 (A) 的形式提供。只需确保对于整数类型的实参 num , std :: legendre ( int_num, num ) 与 std :: legendre ( int_num, static_cast < double > ( num ) ) 具有相同效果即可。
示例
#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() { // 点校验 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
参见
|
(C++17)
(C++17)
(C++17)
|
拉盖尔多项式
(函数) |
|
(C++17)
(C++17)
(C++17)
|
埃尔米特多项式
(函数) |
外部链接
| 韦斯坦,埃里克·W.《勒让德多项式》 摘自 MathWorld —— 一个 Wolfram 网络资源。 |