命名空间
变体
操作

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

来自 cppreference.cn
 
 
实验性
技术规范
文件系统库 (filesystem TS)
库基础 (library fundamentals TS)
库基础 2 (library fundamentals TS v2)
库基础 3 (library fundamentals TS v3)
并行扩展 (parallelism TS)
并行扩展 2 (parallelism TS v2)
并发扩展 (concurrency TS)
并发扩展 2 (concurrency TS v2)
概念 (concepts TS)
范围 (ranges TS)
反射 (reflection TS)
数学特殊函数 (special functions TR)
实验性非 TS
模式匹配
线性代数
std::execution
契约
2D 图形
 
 
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) 计算 degree 为 n 和参数为 x 的非伴随 勒让德多项式
2) 一组重载或函数模板,接受任何整型类型的参数。等价于将参数转换为 double 后的 (1)

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

目录

[编辑] 参数

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

[编辑] 返回值

如果未发生错误,则返回 xn 阶非伴随勒让德多项式的值,即
1
2n
n!
dn
dxn
(x2
- 1)n

[编辑] 错误处理

错误可能按照 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
    (3x2
    - 1)
  • legendre(3, x) =
    1
    2
    (5x3
    - 3x)
  • legendre(4, x) =
    1
    8
    (35x4
    - 30x2
    + 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()
{
    // spot-checks
    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

[编辑] 参见

拉盖尔多项式
(函数) [编辑]
埃尔米特多项式
(函数) [编辑]

[编辑] 外部链接

Weisstein, Eric W. "Legendre Polynomial." 来自 MathWorld — Wolfram Web 资源。