命名空间
变体
操作

std::assoc_legendre, std::assoc_legendref, std::assoc_legendrel

来自 cppreference.cn
< cpp‎ | 数值‎ | 特殊函数
 
 
 
 
定义于头文件 <cmath>
(1)
float       assoc_legendre ( unsigned int n, unsigned int m, float x );

double      assoc_legendre ( unsigned int n, unsigned int m, double x );

long double assoc_legendre ( unsigned int n, unsigned int m, long 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 起)
1-3) 计算次数为 n、阶数为 m、参数为 x伴随勒让德多项式 库为参数 x 的所有 cv 非限定浮点类型提供了 std::assoc_legendre 的重载。(C++23 起)
A) 为所有整数类型提供了额外的重载,它们被视为 double

目录

[编辑] 参数

n - 多项式的次数,一个无符号整数值
m - 多项式的阶数,一个无符号整数值
x - 变量,浮点或整数值

[编辑] 返回值

如果没有发生错误,返回参数 x 的伴随勒让德多项式 Pm
n
的值,即 (1-x2
)m/2
dm
dxm
Pn(x)
(其中 Pn(x) 是非伴随勒让德多项式 std::legendre(n, x))。

注意,此定义省略了 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 - x2
)1/2
assoc_legendre(2, 0, x)
1
2
(3x2
- 1)
assoc_legendre(2, 1, x)     3x(1 - x2
)1/2
    
assoc_legendre(2, 2, x) 3(1 - x2
)

不要求完全按照 (A) 提供额外的重载。它们只需足以确保对于整数类型的参数 numstd::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()
{
    // 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

[编辑] 另请参阅

(C++17)(C++17)(C++17)
勒让德多项式
(函数) [编辑]

[编辑] 外部链接

Weisstein, Eric W. "Associated Legendre Polynomial." From MathWorld — A Wolfram Web Resource.