名稱空間
變體
操作

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) 計算階為 n、次為 m、變數為 x伴隨勒讓德多項式
2) 一組過載函式或函式模板,接受任何整型引數。在將引數強制轉換為 double 後,等效於 (1)

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

目錄

[編輯] 引數

n - 多項式的次數,一個無符號整型值
m - 多項式的階數,一個無符號整數型別的值
x - 引數,浮點型別或整型值

[編輯] 返回值

如果沒有發生錯誤,則返回 x 的伴隨勒讓德多項式 Pm
n
的值,即 (1 - x2
)m/2
dm
dxm
Pn(x)
(其中 Pn(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
    )

[編輯] 示例

(如 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

[編輯] 參閱

勒讓德多項式
(function) [編輯]

[編輯] 外部連結

Weisstein, Eric W. "伴隨勒讓德多項式。" 來自 MathWorld——A Wolfram Web Resource。