命名空间
变体
操作

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

来自 cppreference.cn
 
 
 
 
定义于头文件 <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连带勒让德多项式 库为所有 cv 限定的浮点类型作为参数 x 的类型提供了 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. "连带勒让德多项式。" 来自 MathWorld — Wolfram Web 资源。