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。 库为所有 cv 无限定浮点类型提供
std::sph_legendre
的重载,作为参数 theta 的类型。(始于 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. “球谐函数。” 来自 MathWorld — Wolfram Web 资源。 |