std::sph_legendre, std::sph_legendref, std::sph_legendrel
来自 cppreference.cn
定义于头文件 <cmath> |
||
(1) | ||
float sph_legendre ( unsigned l, unsigned m, float theta ); double sph_legendre ( unsigned l, unsigned m, 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 | - | 以弧度测量的极角 |
[编辑] 返回值
如果没有错误发生,返回 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() { // 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
[编辑] 参阅
(C++17)(C++17)(C++17) |
伴随勒让德多项式 (函数) |
[编辑] 外部链接
Weisstein, Eric W. "Spherical Harmonic." From MathWorld — A Wolfram Web Resource. |