Namespaces
Variants

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

From cppreference.net
定义于头文件 <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 前)
/* 浮点类型 */ 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 限定符的浮点类型提供了 std::sph_legendre 的重载版本,这些类型作为参数 theta 的类型。 (自 C++23 起)
A) 为所有整数类型提供了额外的重载,这些类型将被视为 double

目录

参数

l - 阶数
m - 级数
theta - 极角,以弧度为单位

返回值

If no errors occur, returns the value of the spherical associated Legendre function (that is, spherical harmonic with ϕ = 0) of l , m , and theta , where the spherical harmonic function is defined as Y m
l
(theta,ϕ) = (-1) m
[
(2l+1)(l-m)!
4π(l+m)!
] 1/2
P m
l
(cos(theta))e imϕ
where P m
l
(x)
is std:: assoc_legendre ( l, m, x ) ) and |m|≤l .

注意 Condon-Shortley 相位项 (-1) m
包含在此定义中,因为该相位项在 std::assoc_legendre P m
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 << "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

参见

连带勒让德多项式
(函数)

外部链接

韦斯坦,埃里克·W《球谐函数》 摘自 MathWorld —— 一个 Wolfram 网络资源。