std::assoc_legendre, std::assoc_legendref, std::assoc_legendrel
來自 cppreference.com
< cpp | experimental | 特殊函式
double assoc_legendre( unsigned int n, unsigned int m, double x ); double assoc_legendre( unsigned int n, unsigned int m, float x ); |
(1) | |
double assoc_legendre( unsigned int n, unsigned int m, IntegralType x ); |
(2) | |
與所有特殊函式一樣,僅當實現定義了 __STDCPP_MATH_SPEC_FUNCS__
的值至少為 201003L 且使用者在包含任何標準庫標頭檔案之前定義了 __STDCPP_WANT_MATH_SPEC_FUNCS__
時,才保證 assoc_legendre
在 <cmath>
中可用。
目錄 |
[編輯] 引數
n | - | 多項式的次數,一個無符號整型值 |
m | - | 多項式的階數,一個無符號整數型別的值 |
x | - | 引數,浮點型別或整型值 |
[編輯] 返回值
如果沒有發生錯誤,則返回 x 的伴隨勒讓德多項式 Pmn 的值,即 (1 - x2
)m/2
dm |
dxm |
[編輯] 錯誤處理
錯誤可能按照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) =
(3x21 2
- 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。