std:: assoc_legendre, std:: assoc_legendref, std:: assoc_legendrel
|
定义于头文件
<cmath>
|
||
| (1) | ||
|
float
assoc_legendre
(
unsigned
int
n,
unsigned
int
m,
float
x
)
;
double
assoc_legendre
(
unsigned
int
n,
unsigned
int
m,
double
x
)
;
|
(C++17 起)
(C++23 前) |
|
|
/* 浮点类型 */
assoc_legendre
(
unsigned
int
n,
unsigned
int
m,
/* 浮点类型 */ x ) ; |
(C++23 起) | |
|
float
assoc_legendref
(
unsigned
int
n,
unsigned
int
m,
float
x
)
;
|
(2) | (C++17 起) |
|
long
double
assoc_legendrel
(
unsigned
int
n,
unsigned
int
m,
long
double
x
)
;
|
(3) | (C++17 起) |
|
定义于头文件
<cmath>
|
||
|
template
<
class
Integer
>
double assoc_legendre ( unsigned int n, unsigned int m, Integer x ) ; |
(A) | (C++17 起) |
std::assoc_legendre
的重载版本,作为参数
x
的类型。
(C++23 起)
目录 |
参数
| n | - | 多项式次数,无符号整数值 |
| m | - | 多项式阶数,无符号整数值 |
| x | - | 函数参数,浮点数或整数值 |
返回值
If no errors occur, value of the associated Legendre polynomial P mn of x , that is (1-x 2
) m/2
|
d
m
|
|
dx
m
|
请注意,本定义中省略了
Condon-Shortley 相位项
(-1)
m
。
错误处理
错误报告方式遵循 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
中找到,即
boost::math::legendre_p
,但 boost.math 的定义包含了 Condon-Shortley 相位项。
前几个关联勒让德多项式为:
| 函数 | 多项式 | ||
|---|---|---|---|
| assoc_legendre ( 0 , 0 , x ) | 1 | ||
| assoc_legendre ( 1 , 0 , x ) | x | ||
| assoc_legendre ( 1 , 1 , x ) |
(1 - x
2
) 1/2 |
||
| assoc_legendre ( 2 , 0 , x ) |
- 1) |
||
| assoc_legendre ( 2 , 1 , x ) |
3x(1 - x
2
) 1/2 |
||
| assoc_legendre ( 2 , 2 , x ) |
3(1 - x
2
) |
额外的重载不需要完全按照 (A) 的形式提供。只需确保对于整数类型的实参 num , std :: assoc_legendre ( int_num1, int_num2, num ) 与 std :: assoc_legendre ( int_num1, int_num2, static_cast < double > ( num ) ) 具有相同效果即可。
示例
#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() { // 点校验 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
参见
|
(C++17)
(C++17)
(C++17)
|
勒让德多项式
(函数) |
外部链接
| 魏斯坦, 埃里克·W. "连带勒让德多项式." 摘自 MathWorld —— 一个 Wolfram 网络资源。 |