# NAG Library Function Documentnag_jacobian_theta (s21ccc)

## 1  Purpose

nag_jacobian_theta (s21ccc) 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\le 1$.

## 2  Specification

#include <nag.h>
#include <nags.h>

double  nag_jacobian_theta (Integer k, double x, double q,  NagError *fail)

## 3  Description

nag_jacobian_theta (s21ccc) 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

$θ 0 x,q = 1 + 2 ∑ n=1 ∞ -1 n q n 2 cos 2 n π x , θ 1 x,q = 2 ∑ n=0 ∞ -1 n q n + 1 2 2 sin 2 n + 1 π x , θ 2 x,q = 2 ∑ n=0 ∞ q n + 1 2 2 cos 2 n + 1 π x , θ 3 x,q = 1 + 2 ∑ n=1 ∞ q n 2 cos 2 n π x , θ 4 x,q = θ 0 x,q ,$
where $x$ and $q$ (the nome) are real with $0\le q\le 1$. Note that ${\theta }_{1}\left(x-\frac{1}{2},1\right)$ is undefined if $\left(x-\frac{1}{2}\right)$ is an integer, as is ${\theta }_{2}\left(x,1\right)$ if $x$ is an integer; otherwise, ${\theta }_{\mathit{i}}\left(x,1\right)=0$, for $\mathit{i}=0,1,\dots ,4$.
These functions are important in practice because every one of the Jacobian elliptic functions (see nag_jacobian_elliptic (s21cbc)) 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., Abramowitz and Stegun (1972), 16.27) 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.
nag_jacobian_theta (s21ccc) 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 $\left(n=0\right)$ of the transformed series

$θ 1 t,q = 2 λ π e - λ t 2 ∑ n=0 ∞ -1 n e - λ n + 1 2 2 sinh 2 n + 1 λ t$
and ${\theta }_{3}$ is set equal to the first two terms (i.e., $n\le 1$) of

$θ 3 t,q = λ π e - λ t 2 1 + 2 ∑ n=1 ∞ e - λ n 2 cosh 2 n λ 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  Arguments

1:     k – IntegerInput
On entry: the function ${\theta }_{\mathrm{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 – doubleInput
On entry: the argument $x$ of the function.
Constraints:
• x must not be an integer when ${\mathbf{q}}=1.0$ and ${\mathbf{k}}=2$ ;
• $\left({\mathbf{x}}-0.5\right)$ must not be an integer when ${\mathbf{q}}=1.0$ and ${\mathbf{k}}=1$. .
3:     q – doubleInput
On entry: the argument $q$ of the function.
Constraint: $0.0\le {\mathbf{q}}\le 1.0$.
4:     fail – NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INFINITE
The evaluation has been abandoned because the function value is infinite.
NE_INT
On entry, ${\mathbf{k}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{k}}\le 4$.
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 contact NAG for assistance.
NE_REAL
On entry, ${\mathbf{q}}=〈\mathit{\text{value}}〉$.
Constraint: $0.0\le {\mathbf{q}}\le 1.0$.
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: $\left({\mathbf{x}}-0.5\right)$ must not be an integer when ${\mathbf{q}}=1.0$ and ${\mathbf{k}}=1$.
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$.
Constraint: x must not be an integer when ${\mathbf{q}}=1.0$ and ${\mathbf{k}}=2$.

## 7  Accuracy

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

None.

## 9  Example

The example program 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 (s21ccce.c)

### 9.2  Program Data

Program Data (s21ccce.d)

### 9.3  Program Results

Program Results (s21ccce.r)
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 70, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.6319827437400818, "perplexity_flag": "middle"}