double sph_legendre ( unsigned l, unsigned m, double θ ); double sph_legendre ( unsigned l, unsigned m, float θ ); double sph_legendre ( unsigned l, unsigned m, long double θ ); float sph_legendref( unsigned l, unsigned m, float θ ); long double sph_legendrel( unsigned l, unsigned m, long double θ ); | (1) | (since C++17) |
double sph_legendre ( unsigned l, unsigned m, Integral θ ); | (2) | (since C++17) |
l
, order m
, and polar angle θ
.double
.l | - | degree |
m | - | order |
θ | - | polar angle, measured in radians |
l
, m
, and θ
, where the spherical harmonic function is defined as Ym(2l+1)(l-m)! |
4π(l+m)! |
std::assoc_legendre(l,m,x)
) and |m|≤l Note that the Condon-Shortley phase term (-1)m
is included in this definition because it is omitted from the definition of Pm
l in std::assoc_legendre
.
Errors may be reported as specified in math_errhandling.
Implementations that do not support C++17, but support ISO 29124:2010, provide this function if __STDCPP_MATH_SPEC_FUNCS__
is defined by the implementation to a value at least 201003L and if the user defines __STDCPP_WANT_MATH_SPEC_FUNCS__
before including any standard library headers.
Implementations that do not support ISO 29124:2010 but support TR 19768:2007 (TR1), provide this function in the header tr1/cmath
and namespace std::tr1
.
An implementation of the spherical harmonic function is available in boost.math, and it reduces to this function when called with the parameter phi set to zero.
#include <cmath> #include <iostream> 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 double pi = std::acos(-1); std::cout << "exact solution = " << 0.25*std::sqrt(7/pi)*(5*std::pow(std::cos(x),3)-3*std::cos(x)) << '\n'; }
Output:
Y_3^0(1.2345) = -0.302387 exact solution = -0.302387
Weisstein, Eric W. "Spherical Harmonic." From MathWorld--A Wolfram Web Resource.
(C++17)(C++17)(C++17)
| associated Legendre polynomials (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/numeric/special_math/sph_legendre