s22aa 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$.

# Syntax

C#
```public static void s22aa(
int mode,
double x,
int m,
int nl,
double[] p,
out int ifail
)```
Visual Basic
```Public Shared Sub s22aa ( _
mode As Integer, _
x As Double, _
m As Integer, _
nl As Integer, _
p As Double(), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void s22aa(
int mode,
double x,
int m,
int nl,
array<double>^ p,
[OutAttribute] int% ifail
)```
F#
```static member s22aa :
mode : int *
x : float *
m : int *
nl : int *
p : float[] *
ifail : int byref -> unit
```

#### Parameters

mode
Type: System..::..Int32
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$.
x
Type: System..::..Double
On entry: the argument $x$ of the function.
Constraint: $\mathrm{abs}\left({\mathbf{x}}\right)\le 1.0$.
m
Type: System..::..Int32
On entry: the order $m$ of the function.
Constraint: $\mathrm{abs}\left({\mathbf{m}}\right)\le 27$.
nl
Type: System..::..Int32
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)$.
p
Type: array<System..::..Double>[]()[][]
An array of size [$0:{\mathbf{nl}}$]
On exit: the required sequence of function values as follows:
• if ${\mathbf{mode}}=1$, ${\mathbf{p}}\left[n\right]$ contains ${P}_{n}^{m}\left(x\right)$, for $\mathit{n}=0,1,\dots ,N$;
• if ${\mathbf{mode}}=2$, ${\mathbf{p}}\left[n\right]$ contains $\overline{{P}_{n}^{m}}\left(x\right)$, for $\mathit{n}=0,1,\dots ,N$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

s22aa evaluates a sequence of values for either the unnormalized or normalized Legendre ($m=0$) or associated Legendre ($m\ne 0$) 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
 $Pnmx=1-x2m/2dmdxmPnx if ​m≥0,Pnmx=n+m!n-m!Pn-mx if ​m<0 andPnm¯x=2n+12n-m!n+m!Pnmx$
respectively; ${P}_{n}\left(x\right)$ is the (unassociated) Legendre polynomial of degree $n$ given by
 $Pnx≡Pn0x=12nn!dndxnx2-1n$
(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.
s22aa is based on a standard recurrence relation described in Section 8.5.3 of Abramowitz and Stegun (1972). 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 [Parameters]) to zero whenever the required function is not defined for certain values of $m$ and $n$ (e.g., $m=-5$ and $n=3$).

# References

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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, $\mathrm{abs}\left({\mathbf{x}}\right)>1.0$, or ${\mathbf{mode}}\ne 1$ or $2$, or ${\mathbf{nl}}<0$, or ${\mathbf{nl}}>100$ when ${\mathbf{m}}=0$, or $\mathrm{abs}\left({\mathbf{m}}\right)>27$, or ${\mathbf{nl}}+\mathrm{abs}\left({\mathbf{m}}\right)>55$ when ${\mathbf{m}}\ne 0$.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# 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.

None.

# Example

This example 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.

Example program (C#): s22aae.cs

Example program data: s22aae.d

Example program results: s22aae.r