名前空間
変種
操作

std::legendre, std::legendref, std::legendrel

From cppreference.com
 
 
 
 
double      legendre( unsigned int n, double x );

double      legendre( unsigned int n, float x );
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)
double      legendre( unsigned int n, IntegralType x );
(2)
1) 非関連ルジャンドル多項式を計算します。次数は n、引数は x です。
2) 整数型 (integral type) の引数を受け付けるオーバーロードのセット、または関数テンプレートです。引数を double にキャストした後の (1) と同等です。

すべての特殊関数と同様に、legendre<cmath> で利用可能であることは、実装によって __STDCPP_MATH_SPEC_FUNCS__ が 201003L 以上の値に定義されており、かつユーザーが標準ライブラリヘッダをインクルードする前に __STDCPP_WANT_MATH_SPEC_FUNCS__ を定義した場合にのみ保証されます。

目次

[編集] パラメータ

n - 多項式の次数
x - 引数。浮動小数点型または整数型の値。

[編集] 戻り値

エラーが発生しなかった場合、次数 n の非関連ルジャンドル多項式
1
2n
n!
dn
dxn
(x2
- 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) =
    1
    2
    (3x2
    - 1)
  • legendre(3, x) =
    1
    2
    (5x3
    - 3x)
  • legendre(4, x) =
    1
    8
    (35x4
    - 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." From MathWorld — A Wolfram Web Resource.
English 日本語 中文(简体) 中文(繁體)