legendre#
This module implements the Associated Legendre Polynomials, \(P_n^m(x)\), and their first two derivatives in support of the spherical_harmonic
module. If \(m=0\), they reduce to the unassociated Legendre polynomials.
- orthopoly.legendre.legen_norm(n, m)#
Evaluates the normalization factor for the associated Legendre polynomials,
\begin{equation} \sqrt{\frac{(2n + 1) (n - m)!}{4 \pi (n + m)!}} \end{equation}with an iteration instead of direct factorials to help avoid overflow. This function is not used in the other functions in this module, which compute the normalized polynomials without directly calculating the normalization factor. However, it can be used to switch between normalized and unnormalized values.
- Parameters:
n (int) – degree of polynomial
m (int) – order of polynomial (m >= 0)
- Returns:
normalization factor
- orthopoly.legendre.legen_hat(xhat, n, m)#
Evaluates the normalized associated Legendre function of degree n and order m, \(P_n^m(x)\), through a three term recurrence relationship. These are normalized and the normalization factor is:
\begin{equation} \sqrt{\frac{(2n + 1) (n - m)!}{4 \pi (n + m)!}} \end{equation}- as defined in chapter 6 of the reference below, but without the extra factor of \(-1^m\)
Press, William H., et al. Numerical recipes 3rd edition: The art of scientific computing. Cambridge university press, 2007.
- Parameters:
xhat (array/float) – evaluation point in \([-1,1]\) (can be an array)
n (int) – degree of polynomial
m (int) – order of polynomial (m >= 0)
- Returns:
evaluated function, \(P_n^m(\hat{x})\)
- orthopoly.legendre.legen(x, n, m, xa=-1, xb=1)#
Evaluates the normalized associated Legendre function of degree n and order m, \(P_n^m(x)\), through a three term recurrence relationship, over the interval \([x_a,x_b]\). These are normalized and the normalization factor is:
\begin{equation} \sqrt{\frac{(2n + 1) (n - m)!}{4 \pi (n + m)!}} \end{equation}- as defined in chapter 6 of the reference below, but without the extra factor of \(-1^m\)
Press, William H., et al. Numerical recipes 3rd edition: The art of scientific computing. Cambridge university press, 2007.
- Parameters:
x (array/float) – evaluation point in \([x_a,x_b]\) (can be an array)
n (int) – degree of polynomial
m (int) – order of polynomial (m >= 0)
xa (float) – lower limit of evaluation interval
xb (float) – upper limit of evaluation interval
- Returns:
evaluated function, \(P_n^m(x)\)
- orthopoly.legendre.legen_theta(t, n, m)#
Evaluates the normalized associated Legendre function \(P_n^m(cos(\theta))\) with a colatitude argument in \([0,\pi]\) instead of \([-1,1]\)
- Parameters:
t (array/float) – colatitude evaluation point(s) in \([0,\pi]\) (can be an array)
n (int) – degree of polynomial
m (int) – order of polynomial (m >= 0)
- Returns:
evaluated function, \(P_n^m[\cos(\theta)]\)
- orthopoly.legendre.dlegen_theta(t, n, m)#
- Evaluates the first derivative of the normalized associated Legendre function with colatitude argument, \(d P_n^m / d \theta\). This can be used in computing the gradient of spherical harmonics. The algorithm is detailed in:
Bosch, W. “On the computation of derivatives of Legendre functions.” Physics and Chemistry of the Earth, Part A: Solid Earth and Geodesy 25.9-11 (2000): 655-659.
- Parameters:
t (array/float) – colatitude evaluation point(s) in \([0,\pi]\) (can be an array)
n (int) – degree of polynomial
m (int) – order of polynomial (m >= 0)
- Returns:
evaluated first derivative, \(d P_n^m / d \theta\)
- orthopoly.legendre.ddlegen_theta(t, n, m)#
- Evaluates the second derivative of the normalized associated Legendre function with colatitude argument, \(d^2 P_n^m / d \theta^2\). This can be used in computing the Laplacian of spherical harmonics. The algorithm is detailed in:
Bosch, W. “On the computation of derivatives of Legendre functions.” Physics and Chemistry of the Earth, Part A: Solid Earth and Geodesy 25.9-11 (2000): 655-659.
- Parameters:
t (array/float) – colatitude evaluation point(s) in \([0,\pi]\) (can be an array)
n (int) – degree of polynomial
m (int) – order of polynomial (m >= 0)
- Returns:
evaluated second derivative, \(d^2 P_n^m / d \theta^2\)