std::sph_le...ph_legendrel(3)
hey bestie π welcome to the std::sph_le...ph_legendrel(3) page from the C++ Standard Libary manual. we are doing spherical associated Legendre functions today, and yes the math is giving main character energy β¨ stay with me, it slays.
πΈ NAME πΈ
std::sph_legendre, std::sph_legendref, std::sph_legendrel β std::sph_legendre, std::sph_legendref, std::sph_legendrel
π¦ Synopsis π¦
okay so this is the synopsis exactly as the page serves it β yes itβs a little chaotic, we love her π
Defined in header <cmath>
float sph_legendre ( unsigned l, unsigned m, float theta
);
double sph_legendre ( unsigned l, unsigned m, double
(since C++17)
theta );
(until C++23)
long double sph_legendre ( unsigned l, unsigned m, long double
theta );
/* floating-point-type */ sph_legendre( unsigned l, unsigned
m,
(since C++23)
/* floating-point-type (1)
*/ theta );
float sph_legendref( unsigned l, unsigned m, float theta
(2) (since C++17)
);
long double sph_legendrel( unsigned l, unsigned m, long double
(3) (since C++17)
theta );
Additional overloads
Defined in header <cmath>
template< class Integer >
double sph_legendre ( unsigned l, unsigned m, Integer
(A) (since C++17)
theta );
1-3) Computes the spherical associated Legendre function of degree l, order m, and polar angle theta.
The library provides overloads of std::sph_legendre for all cv-unqualified floating-point types as the type of the parameter theta. (since C++23)
A) Additional overloads are provided for all integer types, which are treated as double.
π Parameters π
lβ degreemβ orderthetaβ polar angle, measured in radians
π Return value π
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
Ym
l(theta,Ο) = (-1)m
[
(2l+1)(l-m)!
4Ο(l+m)!
]1/2
Pm
l(cos(theta))eimΟ
where Pm l(x) is 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.
π Error handling π
Errors may be reported as specified in math_errhandling.
- If the argument is
NaN,NaNis returned and domain error is not reported. - If
lβ₯128, the behavior is implementation-defined.
bestie, lβ₯128 being implementation-defined means donβt act surprised when your implementation does its own little thing π
πΈ Notes πΈ
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.
The additional overloads are not required to be provided exactly as (A). They only need to be sufficient to ensure that for their argument num of integer type, std::sph_legendre(int_num1, int_num2, num) has the same effect as std::sph_legendre(int_num1, int_num2, static_cast<double>(num)).
π₯ Example π₯
// Run this code
#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';
}
β¨ Output β¨
Y_3^0(1.2345) = -0.302387
exact solution = -0.302387
π See also π
assoc_legendre(C++17)assoc_legendref(C++17)assoc_legendrel(C++17)β associated Legendre polynomials(function)
π External links π
- Weisstein, Eric W. "Spherical Harmonic." From MathWorld β A Wolfram Web Resource.
k bye bestie π«Ά this page came from http://cppreference.com, version/date 2024.06.10, and the footer label is std::sph_le...ph_legendrel(3). now go flex that spherical harmonic knowledge, periodt π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms