Namespaces
Variants

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

From cppreference.net
double assoc_legendre ( unsigned int n, unsigned int m, double x ) ;

double assoc_legendre ( unsigned int n, unsigned int m, float x ) ;
double assoc_legendre ( unsigned int n, unsigned int m, long double x ) ;
float assoc_legendref ( unsigned int n, unsigned int m, float x ) ;

long double assoc_legendrel ( unsigned int n, unsigned int m, long double x ) ;
(1)
double assoc_legendre ( unsigned int n, unsigned int m, IntegralType x ) ;
(2)
1) 计算阶数为 n 、次数为 m 、自变量为 x 连带勒让德多项式
2) 一组重载或函数模板,接受任意 整数类型 的参数。在将参数强制转换为 double 后,等同于 (1)

与所有特殊函数一样,只有当实现将 __STDCPP_MATH_SPEC_FUNCS__ 定义为至少 201003L 的值,且用户在包含任何标准库头文件之前定义了 __STDCPP_WANT_MATH_SPEC_FUNCS__ 时,才保证 assoc_legendre <cmath> 中可用。

目录

参数

n - 多项式次数,无符号整数类型的值
m - 多项式阶数,无符号整数类型的值
x - 参数,浮点数或整数类型的值

返回值

If no errors occur, value of the associated Legendre polynomial P m
n
of x , that is (1 - x 2
) m/2
d m
dx m
P n (x)
, is returned (where P n (x) is the unassociated Legendre polynomial, std:: legendre ( n, x ) ).

错误处理

错误报告方式可按照 math_errhandling 中的规定执行。

  • 若参数为 NaN,则返回 NaN 且不报告定义域错误。
  • |x| > 1 ,可能出现定义域错误。
  • n 大于或等于 128,其行为由实现定义。

注释

不支持 TR 29124 但支持 TR 19768 的实现,会在头文件 tr1/cmath 和命名空间 std::tr1 中提供此函数。

此函数的实现也可 在 boost.math 中找到

前几个关联勒让德多项式为:

  • 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
    2
    (3x 2
    - 1)
  • assoc_legendre(2, 1, x) = -3x(1 - x 2
    ) 1/2
  • assoc_legendre(2, 2, x) = 3(1 - x 2
    )

示例

(在 gcc 6.0 下运行结果如上所示)

#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#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

参见

勒让德多项式
(函数)

外部链接

魏斯斯坦, 埃里克·W. 《连带勒让德多项式》 摘自 MathWorld——沃尔夫ram网络资源。