std::legendre, std::legendref, std::legendrel
提供: cppreference.com
<tbody>
</tbody>
(x2
-1)n
| ヘッダ <cmath> で定義
|
||
double legendre( unsigned int n, double x ); float legendre( unsigned int n, float x ); long 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) | (C++17以上) |
double legendre( unsigned int n, 整数型 x ); |
(2) | (C++17以上) |
引数
| n | - | 多項式の次数 |
| x | - | 引数、浮動小数点型または整数型の値 |
戻り値
エラーが発生しなければ、 x の n 次ルジャンドル多項式、すなわち
| 1 |
| 2n n! |
| dn |
| dxn |
-1)n
の値が返されます。
エラー処理
エラーは 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 でも利用可能です。
最初のいくつかのルジャンドル多項式は以下の通りです。
- 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)
例
Run this code
#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
関連項目
(C++17)(C++17)(C++17) |
ラゲール多項式 (関数) |
(C++17)(C++17)(C++17) |
エルミート多項式 (関数) |
外部リンク
Weisstein, Eric W. "Legendre Polynomial." From MathWorld--A Wolfram Web Resource.