std::sph_legendre, std::sph_legendref, std::sph_legendrel
出自cppreference.com
< cpp | numeric | special functions
在標頭 <cmath> 定義
|
||
(1) | ||
float sph_legendre ( unsigned l, unsigned m, float theta ); double sph_legendre ( unsigned l, unsigned m, double theta ); |
(C++17 起) (C++23 前) |
|
/* 浮點數類型 */ sph_legendre( unsigned l, unsigned m, /* 浮點數類型 */ 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 的球關聯勒讓德函數。標準庫提供所有以無 cv 限定的浮點數類型作為形參 theta 的類型的
std::sph_legendre
重載。(C++23 起)A) 為所有整數類型提供額外重載,將它們當做 double。
目錄 |
[編輯] 參數
l | - | 次數 |
m | - | 階數 |
theta | - | 極角,以弧度度量 |
[編輯] 返回值
如果沒有發生錯誤,那麼返回 l、m 和 theta 的球關聯勒讓德函數(即 ϕ = 0 下的球諧函數)的值,其中球諧函數定義為 Yml(theta,ϕ) = (-1)m
[
(2l+1)(l-m)! |
4π(l+m)! |
Pm
l(cos(theta))eimϕ
,其中 Pm
l(x) 是 std::assoc_legendre(l, m, x)) 且 |m|≤l。
注意此函數定義包含 Condon-Shortley 相位項 (-1)m
,因為以 std::assoc_legendre 定義的 Pm
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) 的形式提供。它們只需要能夠對它們的整數類型實參 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() { // 对于 l=3, m=0 的点检查 double x = 1.2345; std::cout << "Y_3^0(" << x << ") = " << std::sph_legendre(3, 0, x) << '\n'; // 准确解 std::cout << "准确解 = " << 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 准确解 = -0.302387
[編輯] 參閱
(C++17)(C++17)(C++17) |
連帶勒讓德多項式 (函數) |
[編輯] 外部鏈接
Weisstein, Eric W. 「球諧」來自 MathWorld--A Wolfram Web Resource。 |