# NAG FL Interfaces22aaf (legendre_​p)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine s22aaf ( mode, x, m, nl, p,
 Integer, Intent (In) :: mode, m, nl Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x Real (Kind=nag_wp), Intent (Out) :: p(0:nl)
#include <nag.h>
 void s22aaf_ (const Integer *mode, const double *x, const Integer *m, const Integer *nl, double p[], Integer *ifail)
The routine may be called by the names s22aaf or nagf_specfun_legendre_p.

## 3Description

s22aaf 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
 $Pnm(x) = (1-x2)m/2 dmdxm Pn(x) if ​m≥0, Pnm(x) = (n+m)! (n-m)! Pn-m(x) if ​m<0 and Pnm¯(x) = (2n+1) 2 (n-m)! (n+m)! Pnm(x)$
respectively; ${P}_{n}\left(x\right)$ is the (unassociated) Legendre polynomial of degree $n$ given by
 $Pn(x)≡Pn0(x)=12nn! dndxn (x2-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.
s22aaf 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 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$).
Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications

## 5Arguments

1: $\mathbf{mode}$Integer Input
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: $\mathbf{x}$Real (Kind=nag_wp) Input
On entry: the argument $x$ of the function.
Constraint: $\mathrm{abs}\left({\mathbf{x}}\right)\le 1.0$.
3: $\mathbf{m}$Integer Input
On entry: the order $m$ of the function.
Constraint: $\mathrm{abs}\left({\mathbf{m}}\right)\le 27$.
4: $\mathbf{nl}$Integer Input
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: $\mathbf{p}\left(0:{\mathbf{nl}}\right)$Real (Kind=nag_wp) array Output
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$.
6: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, $|{\mathbf{m}}|=⟨\mathit{\text{value}}⟩$.
Constraint: $|{\mathbf{m}}|\le 27$.
On entry, $|{\mathbf{x}}|=⟨\mathit{\text{value}}⟩$.
Constraint: $|{\mathbf{x}}|\le 1.0$.
On entry, ${\mathbf{mode}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{mode}}\le 2$.
On entry, ${\mathbf{mode}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{mode}}\ge 1$.
On entry, ${\mathbf{nl}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nl}}\le 100$ when ${\mathbf{m}}=0$.
On entry, ${\mathbf{nl}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nl}}\ge 0$.
On entry, ${\mathbf{nl}}=⟨\mathit{\text{value}}⟩$.
Constraint: when $|{\mathbf{m}}|\ne 0$, ${\mathbf{nl}}\ge 0$.
On entry, ${\mathbf{nl}}=⟨\mathit{\text{value}}⟩$ and $|{\mathbf{m}}|=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{nl}}+|{\mathbf{m}}|\le 55$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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.

## 8Parallelism and Performance

s22aaf is not threaded in any implementation.

None.

## 10Example

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.

### 10.1Program Text

Program Text (s22aafe.f90)

### 10.2Program Data

Program Data (s22aafe.d)

### 10.3Program Results

Program Results (s22aafe.r)