# NAG FL Interfaces22caf (mathieu_​ang_​periodic_​real)

## 1Purpose

s22caf calculates real-valued periodic angular Mathieu functions ($c{e}_{m}\left(x,q\right)$ or $s{e}_{m}\left(x,q\right)$) and/or their first derivatives, where $c{e}_{m}\left(x,q\right)$ and $s{e}_{m}\left(x,q\right)$ are solutions to the Mathieu differential equation $\frac{{d}^{2}y}{d{x}^{2}}+\left[a-2q\mathrm{cos}\left(2x\right)\right]y=0$.

## 2Specification

Fortran Interface
 Subroutine s22caf ( q, mode, n, x, f, a,
 Integer, Intent (In) :: ordval, parity, mode, n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: q, x(n) Real (Kind=nag_wp), Intent (Out) :: f(n), f_deriv(n), a
#include <nag.h>
 void s22caf_ (const Integer *ordval, const double *q, const Integer *parity, const Integer *mode, const Integer *n, const double x[], double f[], double f_deriv[], double *a, Integer *ifail)
The routine may be called by the names s22caf or nagf_specfun_mathieu_ang_periodic_real.

## 3Description

s22caf calculates an approximation to $c{e}_{m}\left(x,q\right)$ and/or ${ce}_{m}^{\prime }\left(x,q\right)$, or $s{e}_{m}\left(x,q\right)$ and/or ${se}_{m}^{\prime }\left(x,q\right)$, where $c{e}_{m}\left(x,q\right)$ and $s{e}_{m}\left(x,q\right)$ are respectively the even and odd parity real-valued periodic angular Mathieu functions, for an array of values of $x$, and for integer order value $m$, where $m\ge 0$ for even parity, and $m\ge 1$ for odd parity. The routine also returns values of $a$ for these periodic Mathieu functions, this is known as the characteristic value or eigenvalue.
The solutions are computed by approximating Mathieu functions as Fourier series, where expansion coefficients are obtained by solving the eigenvalue problem generated from the relevant recurrence relation, see Chapter 28 in NIST Digital Library of Mathematical Functions.

## 4References

NIST Digital Library of Mathematical Functions

## 5Arguments

1: $\mathbf{ordval}$Integer Input
On entry: $m$, the order number of the Mathieu function to be computed.
Constraints:
• if ${\mathbf{parity}}=0$ (even Mathieu function), ${\mathbf{ordval}}\ge 0$;
• if ${\mathbf{parity}}=1$ (odd Mathieu function), ${\mathbf{ordval}}\ge 1$.
2: $\mathbf{q}$Real (Kind=nag_wp) Input
On entry: $q$, the Mathieu function parameter.
3: $\mathbf{parity}$Integer Input
On entry: specifies whether to compute even or odd Mathieu function.
${\mathbf{parity}}=0$
Compute even Mathieu function, $c{e}_{m}\left(x,q\right)$.
${\mathbf{parity}}=1$
Compute odd Mathieu function, $s{e}_{m}\left(x,q\right)$.
Constraint: ${\mathbf{parity}}=0$ or $1$.
4: $\mathbf{mode}$Integer Input
On entry: specifies whether the Mathieu function or its derivative is required.
${\mathbf{mode}}=0$
Compute Mathieu function values.
${\mathbf{mode}}=1$
Compute derivative values of Mathieu function.
${\mathbf{mode}}=2$
Compute both Mathieu function and derivative values.
${\mathbf{mode}}=3$
Compute neither Mathieu functions nor derivative values, returns only a (the characteristic value).
Constraint: ${\mathbf{mode}}=0$, $1$, $2$ or $3$.
5: $\mathbf{n}$Integer Input
On entry: $n$, the number of values to compute.
Constraint: ${\mathbf{n}}\ge 0$.
6: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the values of $x$ at which to compute Mathieu function or derivative values.
7: $\mathbf{f}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: if ${\mathbf{mode}}=0$ or $2$, the Mathieu function values $c{e}_{m}\left(x,q\right)$ or $s{e}_{m}\left(x,q\right)$. If ${\mathbf{mode}}=1$ or $3$, f is not used.
8: $\mathbf{f_deriv}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: if ${\mathbf{mode}}=1$ or $2$, the Mathieu function derivative values $c{e}_{m}^{\prime }\left(x,q\right)$ or $s{e}_{m}^{\prime }\left(x,q\right)$. If ${\mathbf{mode}}=0$ or $3$, f_deriv is not used.
9: $\mathbf{a}$Real (Kind=nag_wp) Output
On exit: $a$, the characteristic value for the Mathieu function.
10: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value 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{ordval}}=〈\mathit{\text{value}}〉$ and ${\mathbf{parity}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{parity}}=0$, ${\mathbf{ordval}}\ge 0$ or if ${\mathbf{parity}}=1$, ${\mathbf{ordval}}\ge 1$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{parity}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{parity}}=0$ or $1$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{mode}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mode}}=0$, $1$, $2$ or $3$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 0$.
${\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.

Not applicable.

## 8Parallelism and Performance

s22caf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
s22caf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

This example calculates the first four even and odd function and derivative values at $x=0$ for $q=2.0$.

### 10.1Program Text

Program Text (s22cafe.f90)

### 10.2Program Data

Program Data (s22cafe.d)

### 10.3Program Results

Program Results (s22cafe.r)