# NAG FL Interfaces21caf (jacellip_​real)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

s21caf evaluates the Jacobian elliptic functions sn, cn and dn.

## 2Specification

Fortran Interface
 Subroutine s21caf ( u, m, sn, cn, dn,
 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: u, m Real (Kind=nag_wp), Intent (Out) :: sn, cn, dn
#include <nag.h>
 void s21caf_ (const double *u, const double *m, double *sn, double *cn, double *dn, Integer *ifail)
The routine may be called by the names s21caf or nagf_specfun_jacellip_real.

## 3Description

s21caf evaluates the Jacobian elliptic functions of argument $u$ and argument $m$,
 $sn(u∣m) = sin⁡ϕ, cn(u∣m) = cos⁡ϕ, dn(u∣m) = 1-msin2⁡ϕ,$
where $\varphi$, called the amplitude of $u$, is defined by the integral
 $u=∫0ϕdθ 1-msin2⁡θ .$
The elliptic functions are sometimes written simply as $\mathrm{sn}u$, $\mathrm{cn}u$ and $\mathrm{dn}u$, avoiding explicit reference to the argument $m$.
Another nine elliptic functions may be computed via the formulae
 $cd⁡u = cn⁡u/dn⁡u sd⁡u = sn⁡u/dn⁡u nd⁡u = 1/dn⁡u dc⁡u = dn⁡u/cn⁡u nc⁡u = 1/cn⁡u sc⁡u = sn⁡u/cn⁡u ns⁡u = 1/sn⁡u ds⁡u = dn⁡u/sn⁡u cs⁡u = cn⁡u/sn⁡u$
(see Abramowitz and Stegun (1972)).
s21caf is based on a procedure given by Bulirsch (1960), and uses the process of the arithmetic-geometric mean ($16.9$ in Abramowitz and Stegun (1972)). Constraints are placed on the values of $u$ and $m$ in order to avoid the possibility of machine overflow.

## 4References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Bulirsch R (1960) Numerical calculation of elliptic integrals and elliptic functions Numer. Math. 7 76–90

## 5Arguments

1: $\mathbf{u}$Real (Kind=nag_wp) Input
2: $\mathbf{m}$Real (Kind=nag_wp) Input
On entry: the argument $u$ and the argument $m$ of the functions, respectively.
Constraints:
• $\mathrm{abs}\left({\mathbf{u}}\right)\le \sqrt{\lambda }$, where $\lambda =1/{\mathbf{x02amf}}$;
• if $\mathrm{abs}\left({\mathbf{u}}\right)<1/\sqrt{\lambda }$, $\mathrm{abs}\left({\mathbf{m}}\right)\le \sqrt{\lambda }$.
3: $\mathbf{sn}$Real (Kind=nag_wp) Output
4: $\mathbf{cn}$Real (Kind=nag_wp) Output
5: $\mathbf{dn}$Real (Kind=nag_wp) Output
On exit: the values of the functions $\mathrm{sn}u$, $\mathrm{cn}u$ and $\mathrm{dn}u$, 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, $|{\mathbf{u}}|$ is too large: $|{\mathbf{u}}|=⟨\mathit{\text{value}}⟩$ it must be less than $⟨\mathit{\text{value}}⟩$.
${\mathbf{ifail}}=2$
On entry, $|{\mathbf{m}}|$ is too large when used in conjunction with the supplied argument u: $|{\mathbf{m}}|=⟨\mathit{\text{value}}⟩$ it must be less than $⟨\mathit{\text{value}}⟩$.
${\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

s21caf is not threaded in any implementation.

None.

## 10Example

This example reads values of the argument $u$ and argument $m$ from a file, evaluates the function and prints the results.

### 10.1Program Text

Program Text (s21cafe.f90)

### 10.2Program Data

Program Data (s21cafe.d)

### 10.3Program Results

Program Results (s21cafe.r)