std::legendre, std::legendref, std::legendrel
來自 cppreference.com
< cpp | experimental | 特殊函式
double legendre( unsigned int n, double x ); double legendre( unsigned int n, float x ); |
(1) | |
double legendre( unsigned int n, IntegralType x ); |
(2) | |
與所有特殊函式一樣,只有當實現定義了 __STDCPP_MATH_SPEC_FUNCS__
的值至少為 201003L 並且使用者在包含任何標準庫標頭檔案之前定義了 __STDCPP_WANT_MATH_SPEC_FUNCS__
時,legendre
才保證在 <cmath>
中可用。
目錄 |
[編輯] 引數
n | - | 多項式的次數 |
x | - | 引數,浮點型別或整型值 |
[編輯] 返回值
如果未發生錯誤,則返回 x 的 n 階非伴隨勒讓德多項式的值,即1 |
2n n! |
dn |
dxn |
- 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) =
(3x21 2
- 1)。 - legendre(3, x) =
(5x31 2
- 3x)。 - legendre(4, x) =
(35x41 8
- 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。 |