名稱空間
變體
操作

std::legendre, std::legendref, std::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      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 次和 x 引數的非伴隨 勒讓德多項式
2) 一組過載函式或函式模板,接受任何整型引數。在將引數轉換為 double 後,等效於 (1)

與所有特殊函式一樣,只有當實現定義了 __STDCPP_MATH_SPEC_FUNCS__ 的值至少為 201003L 並且使用者在包含任何標準庫標頭檔案之前定義了 __STDCPP_WANT_MATH_SPEC_FUNCS__ 時,legendre 才保證在 <cmath> 中可用。

目錄

[編輯] 引數

n - 多項式的次數
x - 引數,浮點型別或整型值

[編輯] 返回值

如果未發生錯誤,則返回 x 的 n 階非伴隨勒讓德多項式的值,即
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 Resource。