S21CCF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentS21CCF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

S21CCF returns the value of one of the Jacobian theta functions ${\theta }_{0}\left(x,q\right)$, ${\theta }_{1}\left(x,q\right)$, ${\theta }_{2}\left(x,q\right)$, ${\theta }_{3}\left(x,q\right)$ or ${\theta }_{4}\left(x,q\right)$ for a real argument $x$ and non-negative $q<1$, via the function name.

## 2  Specification

 FUNCTION S21CCF ( K, X, Q, IFAIL)
 REAL (KIND=nag_wp) S21CCF
 INTEGER K, IFAIL REAL (KIND=nag_wp) X, Q

## 3  Description

S21CCF evaluates an approximation to the Jacobian theta functions ${\theta }_{0}\left(x,q\right)$, ${\theta }_{1}\left(x,q\right)$, ${\theta }_{2}\left(x,q\right)$, ${\theta }_{3}\left(x,q\right)$ and ${\theta }_{4}\left(x,q\right)$ given by
 $θ0x,q = 1+2∑n=1∞-1nqn2cos2nπx, θ1x,q = 2∑n=0∞-1nq n+12 2sin2n+1πx, θ2x,q = 2∑n=0∞q n+12 2cos2n+1πx, θ3x,q = 1+2∑n=1∞qn2cos2nπx, θ4x,q = θ0x,q,$
where $x$ and $q$ (the nome) are real with $0\le q<1$.
These functions are important in practice because every one of the Jacobian elliptic functions (see S21CBF) can be expressed as the ratio of two Jacobian theta functions (see Whittaker and Watson (1990)). There is also a bewildering variety of notations used in the literature to define them. Some authors (e.g., Section 16.27 of Abramowitz and Stegun (1972)) define the argument in the trigonometric terms to be $x$ instead of $\pi x$. This can often lead to confusion, so great care must therefore be exercised when consulting the literature. Further details (including various relations and identities) can be found in the references.
S21CCF is based on a truncated series approach. If $t$ differs from $x$ or $-x$ by an integer when $0\le t\le \frac{1}{2}$, it follows from the periodicity and symmetry properties of the functions that ${\theta }_{1}\left(x,q\right)=±{\theta }_{1}\left(t,q\right)$ and ${\theta }_{3}\left(x,q\right)=±{\theta }_{3}\left(t,q\right)$. In a region for which the approximation is sufficiently accurate, ${\theta }_{1}$ is set equal to the first term ($n=0$) of the transformed series
 $θ1t,q=2λπe-λt2∑n=0∞-1ne-λ n+12 2sinh2n+1λt$
and ${\theta }_{3}$ is set equal to the first two terms (i.e., $n\le 1$) of
 $θ3t,q=λπe-λt2 1+2∑n=1∞e-λn2cosh2nλt ,$
where $\lambda ={\pi }^{2}/\left|{\mathrm{log}}_{\mathrm{e}}q\right|$. Otherwise, the trigonometric series for ${\theta }_{1}\left(t,q\right)$ and ${\theta }_{3}\left(t,q\right)$ are used. For all values of $x$, ${\theta }_{0}$ and ${\theta }_{2}$ are computed from the relations ${\theta }_{0}\left(x,q\right)={\theta }_{3}\left(\frac{1}{2}-\left|x\right|,q\right)$ and ${\theta }_{2}\left(x,q\right)={\theta }_{1}\left(\frac{1}{2}-\left|x\right|,q\right)$.

## 4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Byrd P F and Friedman M D (1971) Handbook of Elliptic Integrals for Engineers and Scientists pp. 315–320 (2nd Edition) Springer–Verlag
Magnus W, Oberhettinger F and Soni R P (1966) Formulas and Theorems for the Special Functions of Mathematical Physics 371–377 Springer–Verlag
Tølke F (1966) Praktische Funktionenlehre (Bd. II) 1–38 Springer–Verlag
Whittaker E T and Watson G N (1990) A Course in Modern Analysis (4th Edition) Cambridge University Press

## 5  Parameters

1:     K – INTEGERInput
On entry: denotes the function ${\theta }_{k}\left(x,q\right)$ to be evaluated. Note that ${\mathbf{K}}=4$ is equivalent to ${\mathbf{K}}=0$.
Constraint: $0\le {\mathbf{K}}\le 4$.
2:     X – REAL (KIND=nag_wp)Input
On entry: the argument $x$ of the function.
3:     Q – REAL (KIND=nag_wp)Input
On entry: the argument $q$ of the function.
Constraint: $0.0\le {\mathbf{Q}}<1.0$.
4:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{K}}<0$, or ${\mathbf{K}}>4$, or ${\mathbf{Q}}<0.0$, or ${\mathbf{Q}}\ge 1.0$,
${\mathbf{IFAIL}}=2$
The evaluation has been abandoned because the function value is infinite. The result is returned as the largest machine representable number (see X02ALF).

## 7  Accuracy

In principle the routine is capable of achieving full relative precision in the computed values. However, the accuracy obtainable in practice depends on the accuracy of the standard elementary functions such as sin and cos.

None.

## 9  Example

This example evaluates ${\theta }_{2}\left(x,q\right)$ at $x=0.7$ when $q=0.4$, and prints the results.

### 9.1  Program Text

Program Text (s21ccfe.f90)

### 9.2  Program Data

Program Data (s21ccfe.d)

### 9.3  Program Results

Program Results (s21ccfe.r)

S21CCF (PDF version)
S Chapter Contents
S Chapter Introduction
NAG Library Manual