Namespaces
Variants

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

From cppreference.net
ヘッダー <cmath> で定義
(1)
float legendre ( unsigned int n, float x ) ;

double legendre ( unsigned int n, double x ) ;

long double legendre ( unsigned int n, long 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 の非随伴 Legendre多項式 を計算する。 ライブラリは、パラメータ x の型として、すべてのcv修飾されていない浮動小数点型に対する std::legendre のオーバーロードを提供する。 (C++23以降)
A) すべての整数型に対して追加のオーバーロードが提供されており、これらは double として扱われます。

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - HTMLタグ、属性、リンク先は一切変更していません - C++関連の専門用語(Parameters、Return value、Error handling、Notes、Example、See also、External links)は原文のまま保持しています - 数値や構造は完全に維持されています - プロフェッショナルな技術文書としての正確性を保っています

パラメータ

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

戻り値

If no errors occur, value of the order- n unassociated Legendre polynomial of x , that is
1
2 n
n!
d n
dx n
(x 2
-1) n
, is returned.

エラー処理

エラーは、 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 )
1
2
(3x 2
- 1)
legendre ( 3 , x )
1
2
(5x 3
- 3x)
legendre ( 4 , x )
1
8
(35x 4
- 30x 2
+ 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()
{
    // スポットチェック
    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." MathWorld — Wolfram Web リソースより。