# NAG FL Interfaces21cbf (jacellip_​complex)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

s21cbf evaluates the Jacobian elliptic functions $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$ for a complex argument $z$.

## 2Specification

Fortran Interface
 Subroutine s21cbf ( z, ak2, sn, cn, dn,
 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: ak2 Complex (Kind=nag_wp), Intent (In) :: z Complex (Kind=nag_wp), Intent (Out) :: sn, cn, dn
#include <nag.h>
 void s21cbf_ (const Complex *z, const double *ak2, Complex *sn, Complex *cn, Complex *dn, Integer *ifail)
The routine may be called by the names s21cbf or nagf_specfun_jacellip_complex.

## 3Description

s21cbf evaluates the Jacobian elliptic functions $\mathrm{sn}\left(z\mid k\right)$, $\mathrm{cn}\left(z\mid k\right)$ and $\mathrm{dn}\left(z\mid k\right)$ given by
 $sn(z∣k) = sin⁡ϕ cn(z∣k) = cos⁡ϕ dn(z∣k) = 1-k2sin2⁡ϕ,$
where $z$ is a complex argument, $k$ is a real argument (the modulus) with ${k}^{2}\le 1$ and $\varphi$ (the amplitude of $z$) is defined by the integral
 $z=∫0ϕdθ 1-k2sin2⁡θ .$
The above definitions can be extended for values of ${k}^{2}>1$ (see Salzer (1962)) by means of the formulae
 $sn(z∣k) = k1sn(kz∣k1) cn(z∣k) = dn(kz∣k1) dn(z∣k) = cn(kz∣k1),$
where ${k}_{1}=1/k$.
Special values include
 $sn(z∣0) = sin⁡z cn(z∣0) = cos⁡z dn(z∣0) = 1 sn(z∣1) = tanh⁡z cn(z∣1) = sech⁡z dn(z∣1) = sech⁡z.$
These functions are often simply written as $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$, thereby avoiding explicit reference to the argument $k$. They can also be expressed in terms of Jacobian theta functions (see s21ccf).
Another nine elliptic functions may be computed via the formulae
 $cd⁡z = cn⁡z/dn⁡z sd⁡z = sn⁡z/dn⁡z nd⁡z = 1/dn⁡z dc⁡z = dn⁡z/cn⁡z nc⁡z = 1/cn⁡z sc⁡z = sn⁡z/cn⁡z ns⁡z = 1/sn⁡z ds⁡z = dn⁡z/sn⁡z cs⁡z = cn⁡z/sn⁡z$
(see Abramowitz and Stegun (1972)).
The values of $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$ are obtained by calls to s21caf. Further details can be found in Section 9.
Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Salzer H E (1962) Quick calculation of Jacobian elliptic functions Comm. ACM 5 399

## 5Arguments

1: $\mathbf{z}$Complex (Kind=nag_wp) Input
On entry: the argument $z$ of the functions.
Constraints:
• $\mathrm{abs}\left(\mathrm{Re}\left({\mathbf{z}}\right)\right)\le =\sqrt{\lambda }$;
• $\mathrm{abs}\left(\mathrm{Im}\left({\mathbf{z}}\right)\right)\le \sqrt{\lambda }$, where $\lambda =1/{\mathbf{x02amf}}$.
2: $\mathbf{ak2}$Real (Kind=nag_wp) Input
On entry: the value of ${k}^{2}$.
Constraint: $0.0\le {\mathbf{ak2}}\le 1.0$.
3: $\mathbf{sn}$Complex (Kind=nag_wp) Output
4: $\mathbf{cn}$Complex (Kind=nag_wp) Output
5: $\mathbf{dn}$Complex (Kind=nag_wp) Output
On exit: the values of the functions $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$, respectively.
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, $|\mathrm{Im}\left({\mathbf{z}}\right)|$ is too large: $|\mathrm{Im}\left({\mathbf{z}}\right)|=⟨\mathit{\text{value}}⟩$. It must be less than $⟨\mathit{\text{value}}⟩$.
On entry, $|\mathrm{Re}\left({\mathbf{z}}\right)|$ is too large: $|\mathrm{Re}\left({\mathbf{z}}\right)|=⟨\mathit{\text{value}}⟩$. It must be less than $⟨\mathit{\text{value}}⟩$.
On entry, ${\mathbf{ak2}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ak2}}\le 1.0$.
On entry, ${\mathbf{ak2}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ak2}}\ge 0.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.

## 7Accuracy

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.

## 8Parallelism and Performance

s21cbf is not threaded in any implementation.

The values of $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$ are computed via the formulae
 $sn⁡z = sn(u,k)dn(v,k′) 1-dn2(u,k)sn2(v,k′) + i cn(u,k)dn(u,k)sn(v,k′)cn(v,k′) 1-dn2(u,k)sn2(v,k′) cn⁡z = cn(u,k)cn(v,k′) 1-dn2(u,k)sn2(v,k′) - i sn(u,k)dn(u,k)sn(v,k′)dn(v,k′) 1-dn2(u,k)sn2(v,k′) dn⁡z = dn(u,k)cn(v,k′)dn(v,k′) 1-dn2(u,k)sn2(v,k′) - i k2sn(u,k)cn(u,k)sn(v,k′) 1-dn2(u,k)sn2(v,k′) ,$
where $z=u+iv$ and ${k}^{\prime }=\sqrt{1-{k}^{2}}$ (the complementary modulus).

## 10Example

This example evaluates $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$ at $z=-2.0+3.0i$ when $k=0.5$, and prints the results.

### 10.1Program Text

Program Text (s21cbfe.f90)

### 10.2Program Data

Program Data (s21cbfe.d)

### 10.3Program Results

Program Results (s21cbfe.r)