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

来自cppreference.com
 
 
实验性
技术规范
文件系统库 (文件系统 TS)
库基础 (库基础 TS)
库基础 2 (库基础 TS v2)
库基础 3 (库基础 TS v3)
并行扩展 (并行 TS)
并行扩展 2 (并行 TS v2)
并发扩展 (并发 TS)
并发扩展 2 (并发 TS v2)
概念 (概念 TS)
范围 (范围 TS)
反射 (反射 TS)
数学特殊函数 (特殊函数 TR)
实验性非 TS 功能特性
模式匹配
线性代数
std::execution
契约
2D 图形
 
 
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) 计算实参 xnm连带勒让德多项式
2) 一组接受任何整数类型实参的重载或函数模板。等价于将实参转型为 double 后的 (1)

Template:cpp/experimental/special math/macro note

参数

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

返回值

如果未发生错误,则返回 x 的连带勒让德多项式的值,即 (1 - x2
)m/2
dm
dxm
P
n
(x)
(其中 P
n
(x)
为非连带勒让德多项式,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 - 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
    )

示例

(works as shown with 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()
{
    // 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

参阅

勒让德多项式
(函数)

外部链接

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