名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | 數值‎ | 特殊函式
 
 
 
 
定義於標頭檔案 <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 - 順序
theta - 以弧度測量的極角

[編輯] 返回值

如果沒有錯誤發生,返回 lmtheta 的球面連帶勒讓德函式(即 ϕ = 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

注意,Condon-Shortley 相位項 (-1)m
包含在此定義中,因為它在 std::assoc_legendrePm
l
的定義中被省略了。

[編輯] 錯誤處理

錯誤可能按 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 設定為零,它會簡化為此函式。

不要求完全按照 (A) 提供額外的過載。它們只需要足以確保對於整數型別的引數 numstd::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." From MathWorld — A Wolfram Web Resource.