s Chapter Contents
s Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_legendre_p (s22aac)

## 1  Purpose

nag_legendre_p (s22aac) returns a sequence of values for either the unnormalized or normalized Legendre functions of the first kind ${P}_{n}^{m}\left(x\right)$ or $\overline{{P}_{n}^{m}}\left(x\right)$ for real $x$ of a given order $m$ and degree $n=0,1,\dots ,N$.

## 2  Specification

 #include #include
 void nag_legendre_p (Integer mode, double x, Integer m, Integer nl, double p[], NagError *fail)

## 3  Description

nag_legendre_p (s22aac) evaluates a sequence of values for either the unnormalized or normalized Legendre $\left(m=0\right)$ or associated Legendre $\left(m\ne 0\right)$ functions of the first kind ${P}_{n}^{m}\left(x\right)$ or $\overline{{P}_{n}^{m}}\left(x\right)$, where $x$ is real with $-1\le x\le 1$, of order $m$ and degree $n=0,1,\dots ,N$ defined by
 $P n m x = 1 - x 2 m/2 d m dx m P n x if ​ m ≥ 0 , P n m x = n+m ! n-m ! P n -m x if ​ m < 0 ​ and ​ P n m ¯ x = 2 n + 1 2 n-m ! n+m ! P n m x$
respectively; ${P}_{n}\left(x\right)$ is the (unassociated) Legendre polynomial of degree $n$ given by
 $P n x ≡ P n 0 x = 1 2 n n ! d n dx n x 2 - 1 n$
(the Rodrigues formula). Note that some authors (e.g., Abramowitz and Stegun (1972)) include an additional factor of ${\left(-1\right)}^{m}$ (the Condon–Shortley Phase) in the definitions of ${P}_{n}^{m}\left(x\right)$ and $\overline{{P}_{n}^{m}}\left(x\right)$. They use the notation ${P}_{mn}\left(x\right)\equiv {\left(-1\right)}^{m}{P}_{n}^{m}\left(x\right)$ in order to distinguish between the two cases.
nag_legendre_p (s22aac) is based on a standard recurrence relation given by Abramowitz and Stegun (Abramowitz and Stegun (1972), 8.5.3). Constraints are placed on the values of $m$ and $n$ in order to avoid the possibility of machine overflow. It also sets the appropriate elements of the array p (see Section 5) to zero whenever the required function is not defined for certain values of $m$ and $n$ (e.g., $m=-5$ and $n=3$).

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications

## 5  Arguments

1:     modeIntegerInput
On entry: indicates whether the sequence of function values is to be returned unnormalized or normalized.
${\mathbf{mode}}=1$
The sequence of function values is returned unnormalized.
${\mathbf{mode}}=2$
The sequence of function values is returned normalized.
Constraint: ${\mathbf{mode}}=1$ or $2$.
2:     xdoubleInput
On entry: the argument $x$ of the function.
Constraint: $\mathrm{abs}\left({\mathbf{x}}\right)\le 1.0$.
3:     mIntegerInput
On entry: the order $m$ of the function.
Constraint: $\mathrm{abs}\left({\mathbf{m}}\right)\le 27$.
4:     nlIntegerInput
On entry: the degree $N$ of the last function required in the sequence.
Constraints:
• ${\mathbf{nl}}\ge 0$;
• if ${\mathbf{m}}=0$, ${\mathbf{nl}}\le 100$;
• if ${\mathbf{m}}\ne 0$, ${\mathbf{nl}}\le 55-\mathrm{abs}\left({\mathbf{m}}\right)$.
5:     p[${\mathbf{nl}}+1$]doubleOutput
On exit: the required sequence of function values as follows:
• if ${\mathbf{mode}}=1$, p$\left(n\right)$ contains ${P}_{\mathit{n}}^{m}\left(x\right)$, for $\mathit{n}=0,1,\dots ,N$;
• if ${\mathbf{mode}}=2$, ${\mathbf{p}}\left[\mathit{n}-1\right]$ contains $\overline{{P}_{\mathit{n}}^{m}}\left(x\right)$, for $\mathit{n}=0,1,\dots ,N$.
6:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: $\mathrm{abs}\left({\mathbf{m}}\right)\le 27$.
On entry, ${\mathbf{mode}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mode}}=1$ or 2.
On entry, ${\mathbf{nl}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nl}}\ge 0$.
NE_INT_2
On entry, ${\mathbf{nl}}=〈\mathit{\text{value}}〉$, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nl}}\le 100$ when ${\mathbf{m}}=0$.
On entry, ${\mathbf{nl}}=〈\mathit{\text{value}}〉$, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nl}}\le 55-\mathrm{abs}\left({\mathbf{m}}\right)$ when ${\mathbf{m}}\ne 0$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please consult NAG for assistance.
NE_REAL
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: $\mathrm{abs}\left({\mathbf{x}}\right)\le 1.0$.

## 7  Accuracy

The computed function values should be accurate to within a small multiple of the machine precision except when underflow (or overflow) occurs, in which case the true function values are within a small multiple of the underflow (or overflow) threshold of the machine.

None.

## 9  Example

The following program reads the values of the arguments $x$, $m$ and $N$ from a file, calculates the sequence of unnormalized associated Legendre function values ${P}_{n}^{m}\left(x\right),{P}_{n+1}^{m}\left(x\right),\dots ,{P}_{n+N}^{m}\left(x\right)$, and prints the results.

### 9.1  Program Text

Program Text (s22aace.c)

### 9.2  Program Data

Program Data (s22aace.d)

### 9.3  Program Results

Program Results (s22aace.r)