名前空間
変種
操作

std::sph_legendre, std::sph_legendref, std::sph_legendrel

From cppreference.com
 
 
 
 
ヘッダー <cmath> で定義
(1)
float       sph_legendre ( unsigned l, unsigned m, float theta );

double      sph_legendre ( unsigned l, unsigned m, double theta );

long double sph_legendre ( unsigned l, unsigned m, long double theta );
(C++17以降)
(C++23まで)
/* floating-point-type */ sph_legendre( unsigned l, unsigned m,
                                        /* floating-point-type */ theta );
(C++23から)
float       sph_legendref( unsigned l, unsigned m, float theta );
(2) (C++17以降)
long double sph_legendrel( unsigned l, unsigned m, long double theta );
(3) (C++17以降)
ヘッダー <cmath> で定義
template< class Integer >
double      sph_legendre ( unsigned l, unsigned m, Integer theta );
(A) (C++17以降)
1-3) 球面調和関数の次数 l、順序 m、極角 theta における球面調和関数を計算します。ライブラリは、パラメータ theta の型として、すべての cv-unqualified な浮動小数点数型に対する std::sph_legendre のオーバーロードを提供します。(C++23 以降)
A) すべての整数型に対する追加のオーバーロードが提供されます。これらは double として扱われます。

目次

[編集] パラメータ

l - 次数
m - order
極角 - 極角。ラジアンで測定されます。

[編集] 戻り値

エラーが発生しなかった場合、次数 l、順序 m、および極角 theta における球面調和関数の値を返します(つまり、ϕ = 0 の球面調和関数)。球面調和関数は次のように定義されます:Ym
l
(theta,ϕ) = (-1)m
[
(2l+1)(l-m)!
4π(l+m)!
]1/2
Pm
l
(cos(theta))eimϕ
ここで、Pm
l
(x)
std::assoc_legendre(l, m, x) であり、|m|≤l です。

Pm
l
の定義において std::assoc_legendre で省略されている Condon-Shortley 位相項 (-1)m
がこの定義に含まれていることに注意してください。

[編集] エラー処理

math_errhandling で指定されたとおりにエラーが報告される場合があります。

  • 引数がNaNの場合、NaNが返され、ドメインエラーは報告されません。
  • l≥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 で利用可能であり、パラメータ phi をゼロに設定して呼び出された場合にこの関数に還元されます。

追加のオーバーロードは、 precisamente (A) のように提供される必要はありません。整数型の引数 num に対して、std::sph_legendre(int_num1, int_num2, num)std::sph_legendre(int_num1, int_num2, static_cast<double>(num)) と同じ効果を持つことを保証するのに十分であればよいです。

[編集]

#include <cmath>
#include <iostream>
#include <numbers>
 
int main()
{
    // spot check for l=3, m=0
    double x = 1.2345;
    std::cout << "Y_3^0(" << x << ") = " << std::sph_legendre(3, 0, x) << '\n';
 
    // exact solution
    std::cout << "exact solution = "
              << 0.25 * std::sqrt(7 / std::numbers::pi)
                  * (5 * std::pow(std::cos(x), 3) - 3 * std::cos(x))
              << '\n';
}

出力

Y_3^0(1.2345) = -0.302387
exact solution = -0.302387

[編集] 関連項目

ルジャンドル陪多項式
(関数) [編集]

[編集] 外部リンク

Weisstein, Eric W. "Spherical Harmonic." MathWorld — A Wolfram Web Resource より。
English 日本語 中文(简体) 中文(繁體)