名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | 數值‎ | 特殊函式
 
 
 
 
定義於標頭檔案 <cmath>
(1)
float       assoc_legendre ( unsigned int n, unsigned int m, float x );

double      assoc_legendre ( unsigned int n, unsigned int m, double x );

long double assoc_legendre ( unsigned int n, unsigned int m, long double x );
(C++17 起)
(直至 C++23)
/* 浮點型別 */ assoc_legendre( unsigned int n, unsigned int m,
                                          /* 浮點型別 */ x );
(C++23 起)
float       assoc_legendref( unsigned int n, unsigned int m, float x );
(2) (C++17 起)
long double assoc_legendrel( unsigned int n, unsigned int m, long double x );
(3) (C++17 起)
定義於標頭檔案 <cmath>
template< class Integer >
double      assoc_legendre ( unsigned int n, unsigned int m, Integer x );
(A) (C++17 起)
1-3) 計算次數為 n、階數為 m、引數為 x伴隨勒讓德多項式 庫為引數 x 的所有 cv 非限定浮點型別提供了 std::assoc_legendre 的過載。(C++23 起)
A) 為所有整數型別提供了額外的過載,它們被視為 double

目錄

[編輯] 引數

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

[編輯] 返回值

如果沒有發生錯誤,返回引數 x 的伴隨勒讓德多項式 Pm
n
的值,即 (1-x2
)m/2
dm
dxm
Pn(x)
(其中 Pn(x) 是非伴隨勒讓德多項式 std::legendre(n, x))。

注意,此定義省略了 Condon-Shortley 相位項 (-1)m

[編輯] 錯誤處理

錯誤可能如 math_errhandling 中指定的那樣報告

  • 如果引數是 NaN,則返回 NaN,不報告域錯誤
  • 如果 |x| > 1,可能會發生域錯誤
  • 如果 n 大於或等於 128,則行為是實現定義的

[編輯] 注意

不支援 C++17 但支援 ISO 29124:2010 的實現,如果 __STDCPP_MATH_SPEC_FUNCS__ 被實現定義為至少 201003L 的值,並且使用者在包含任何標準庫標頭檔案之前定義了 __STDCPP_WANT_MATH_SPEC_FUNCS__,則提供此函式。

不支援 ISO 29124:2010 但支援 TR 19768:2007 (TR1) 的實現,在標頭檔案 tr1/cmath 和名稱空間 std::tr1 中提供此函式。

此函式的實現也在 boost.math 中可用,名為 boost::math::legendre_p,不同之處在於 boost.math 定義包含 Condon-Shortley 相位項。

前幾個伴隨勒讓德多項式是

函式 多項式
    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
)

不要求完全按照 (A) 提供額外的過載。它們只需足以確保對於整數型別的引數 numstd::assoc_legendre(int_num1, int_num2, num) 具有與 std::assoc_legendre(int_num1, int_num2, static_cast<double>(num)) 相同的效果。

[編輯] 示例

#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

[編輯] 另請參閱

(C++17)(C++17)(C++17)
勒讓德多項式
(函式) [編輯]

[編輯] 外部連結

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