std::legendre, std::legendref, std::legendrel
From cppreference.com
< cpp | numeric | special functions
| ヘッダー <cmath> で定義 |
||
| (1) | ||
float legendre ( unsigned int n, float x ); double legendre ( unsigned int n, double x ); |
(C++17以降) (C++23まで) |
|
| /* floating-point-type */ legendre( unsigned int n, /* floating-point-type */ x ); |
(C++23から) | |
| float legendref( unsigned int n, float x ); |
(2) | (C++17以降) |
| long double legendrel( unsigned int n, long double x ); |
(3) | (C++17以降) |
| ヘッダー <cmath> で定義 |
||
| template< class Integer > double legendre ( unsigned int n, Integer x ); |
(A) | (C++17以降) |
1-3) 次数 n と引数 x の非同伴ルジャンドル多項式を計算します。パラメータ x の型がすべての cv 非修飾浮動小数点型であるための
std::legendre のオーバーロードがライブラリによって提供されます。(C++23 以降)A) すべての整数型に対する追加のオーバーロードが提供されます。これらは double として扱われます。
目次 |
[編集] パラメータ
| n | - | 多項式の次数 |
| x | - | 引数、浮動小数点数または整数値 |
[編集] 戻り値
エラーが発生しなかった場合、次数 n の非同伴ルジャンドル多項式 x の値、すなわち| 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 でも利用可能です。
最初のいくつかのルジャンドル多項式は次のようになります。
| Function | 多項式 | ||
|---|---|---|---|
| legendre(0, x) | 1 | ||
| legendre(1, x) | x | ||
| legendre(2, x) |
- 1) | ||
| legendre(3, x) |
- 3x) | ||
| legendre(4, x) |
- 30x2 + 3) |
追加のオーバーロードは (A) とまったく同じように提供される必要はありません。整数型の引数 num に対して、std::legendre(int_num, num) が std::legendre(int_num, static_cast<double>(num)) と同じ効果を持つことを保証するのに十分なだけでよいのです。
[編集] 例
このコードを実行
#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. |