Namespaces
Variants

std:: legendre, std:: legendref, std:: legendrel

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

double legendre ( unsigned int n, float x ) ;
double legendre ( unsigned int n, long double x ) ;
float legendref ( unsigned int n, float x ) ;

long double legendrel ( unsigned int n, long double x ) ;
(1)
double legendre ( unsigned int n, IntegralType x ) ;
(2)
1) 计算 n 次无关联 Legendre 多项式 ,参数为 x
2) 一组重载或函数模板,接受任意 整数类型 参数。在将参数强制转换为 double 后,等同于 (1)

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

目录

参数

n - 多项式的次数
x - 参数,浮点数或整数类型的值

返回值

If no errors occur, value of the order- n unassociated Legendre polynomial of x , that is
1
2 n
n!
d n
dx n
(x 2
- 1) n
, is returned.

错误处理

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

  • 若参数为 NaN,则返回 NaN 且不报告定义域错误。
  • 不要求该函数对 |x| > 1 的情况进行定义。
  • n 大于或等于 128,其行为由实现定义。

注释

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

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

前几个勒让德多项式为:

  • legendre(0, x) = 1 .
  • legendre(1, x) = x .
  • legendre(2, x) =
    1
    2
    (3x 2
    - 1)
    .
  • legendre(3, x) =
    1
    2
    (5x 3
    - 3x)
    .
  • legendre(4, x) =
    1
    8
    (35x 4
    - 30x 2
    + 3)
    .

示例

(在 gcc 6.0 环境下运行结果如图所示)

#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
#include <cmath>
#include <iostream>
double P3(double x)
{
    return 0.5 * (5 * std::pow(x, 3) - 3 * x);
}
double P4(double x)
{
    return 0.125 * (35 * std::pow(x, 4) - 30 * x * x + 3);
}
int main()
{
    // 点校验
    std::cout << std::legendre(3, 0.25) << '=' << P3(0.25) << '\n'
              << std::legendre(4, 0.25) << '=' << P4(0.25) << '\n';
}

输出:

-0.335938=-0.335938
0.157715=0.157715

参见

拉盖尔多项式
(函数)
埃尔米特多项式
(函数)

外部链接

魏斯坦, 埃里克·W. "勒让德多项式." 摘自 MathWorld —— 一个 Wolfram 网络资源。