Common mathematical functions | |||||||||||||||||||||||||||||||
Mathematical special functions(C++17) | |||||||||||||||||||||||||||||||
Mathematical constants(C++20) | |||||||||||||||||||||||||||||||
Basic linear algebra algorithms(C++26) | |||||||||||||||||||||||||||||||
Data-parallel types (SIMD)(C++26) | |||||||||||||||||||||||||||||||
Floating-point environment(C++11) | |||||||||||||||||||||||||||||||
Complex numbers | |||||||||||||||||||||||||||||||
Numeric array (valarray ) | |||||||||||||||||||||||||||||||
Pseudo-random number generation | |||||||||||||||||||||||||||||||
Bit manipulation(C++20) | |||||||||||||||||||||||||||||||
Saturation arithmetic(C++26) | |||||||||||||||||||||||||||||||
Factor operations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Interpolations | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
Generic numeric operations | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
C-style checked integer arithmetic | |||||||||||||||||||||||||||||||
|
Defined in header <cmath> | ||
(1) | ||
float sph_legendre(unsigned l,unsigned m,float theta); double sph_legendre(unsigned l,unsigned m,double theta); | (since C++17) (until C++23) | |
/* floating-point-type */ sph_legendre(unsigned l,unsigned m, /* floating-point-type */ theta); | (since C++23) | |
float sph_legendref(unsigned l,unsigned m,float theta); | (2) | (since C++17) |
longdouble sph_legendrel(unsigned l,unsigned m,longdouble theta); | (3) | (since C++17) |
Defined in header <cmath> | ||
template<class Integer> double sph_legendre(unsigned l,unsigned m, Integer theta); | (A) | (since C++17) |
std::sph_legendre
for all cv-unqualified floating-point types as the type of the parametertheta.(since C++23)Contents |
l | - | degree |
m | - | order |
theta | - | polar angle, measured in radians |
(2l+1)(l-m)! |
4π(l+m)! |
Note that theCondon-Shortley phase term(-1)m
is included in this definition because it is omitted from the definition ofPm
l instd::assoc_legendre.
Errors may be reported as specified inmath_errhandling.
Implementations that do not support C++17, but supportISO 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 headertr1/cmath
and namespacestd::tr1
.
An implementation of the spherical harmonic function is available inboost.math, and it reduces to this function when called with the parameter phi set to zero.
The additional overloads are not required to be provided exactly as(A). They only need to be sufficient to ensure that for their argumentnum of integer type,std::sph_legendre(int_num1, int_num2, num) has the same effect asstd::sph_legendre(int_num1, int_num2,static_cast<double>(num)).
#include <cmath>#include <iostream>#include <numbers> int main(){// spot check for l=3, m=0double x=1.2345;std::cout<<"Y_3^0("<< x<<") = "<< std::sph_legendre(3,0, x)<<'\n'; // exact solutionstd::cout<<"exact solution = "<<0.25*std::sqrt(7/std::numbers::pi)*(5*std::pow(std::cos(x),3)-3*std::cos(x))<<'\n';}
Output:
Y_3^0(1.2345) = -0.302387exact solution = -0.302387
(C++17)(C++17)(C++17) | associated Legendre polynomials (function)[edit] |
Weisstein, Eric W. "Spherical Harmonic." From MathWorld — A Wolfram Web Resource. |