S Chapter Contents
S Chapter Introduction
NAG Library Manual

NAG Library Routine DocumentS21CAF

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

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

2  Specification

 SUBROUTINE S21CAF ( U, M, SN, CN, DN, IFAIL)
 INTEGER IFAIL REAL (KIND=nag_wp) U, M, SN, CN, DN

3  Description

S21CAF evaluates the Jacobian elliptic functions of argument $u$ and parameter $m$,
 $snu∣m = sin⁡ϕ, cnu∣m = cos⁡ϕ, dnu∣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 parameter $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.

4  References

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

5  Parameters

1:     U – REAL (KIND=nag_wp)Input
2:     M – REAL (KIND=nag_wp)Input
On entry: the argument $u$ and the parameter $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:     SN – REAL (KIND=nag_wp)Output
4:     CN – REAL (KIND=nag_wp)Output
5:     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:     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, $\mathrm{abs}\left({\mathbf{U}}\right)>\sqrt{\lambda }$, where $\lambda =1/{\mathbf{X02AMF}}\left(\right)$.
${\mathbf{IFAIL}}=2$
 On entry, $\mathrm{abs}\left({\mathbf{M}}\right)>\sqrt{\lambda }$ and $\mathrm{abs}\left({\mathbf{U}}\right)<1/\sqrt{\lambda }$.

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 reads values of the argument $u$ and parameter $m$ from a file, evaluates the function and prints the results.

9.1  Program Text

Program Text (s21cafe.f90)

9.2  Program Data

Program Data (s21cafe.d)

9.3  Program Results

Program Results (s21cafe.r)