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

# Syntax

C#
```public static void s21ca(
double u,
double m,
out double sn,
out double cn,
out double dn,
out int ifail
)```
Visual Basic
```Public Shared Sub s21ca ( _
u As Double, _
m As Double, _
<OutAttribute> ByRef sn As Double, _
<OutAttribute> ByRef cn As Double, _
<OutAttribute> ByRef dn As Double, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void s21ca(
double u,
double m,
[OutAttribute] double% sn,
[OutAttribute] double% cn,
[OutAttribute] double% dn,
[OutAttribute] int% ifail
)```
F#
```static member s21ca :
u : float *
m : float *
sn : float byref *
cn : float byref *
dn : float byref *
ifail : int byref -> unit
```

#### Parameters

u
Type: System..::..Double
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{x02am}}$;
• if $\mathrm{abs}\left({\mathbf{u}}\right)<1/\sqrt{\lambda }$, $\mathrm{abs}\left({\mathbf{m}}\right)\le \sqrt{\lambda }$.
m
Type: System..::..Double
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{x02am}}$;
• if $\mathrm{abs}\left({\mathbf{u}}\right)<1/\sqrt{\lambda }$, $\mathrm{abs}\left({\mathbf{m}}\right)\le \sqrt{\lambda }$.
sn
Type: System..::..Double%
On exit: the values of the functions $\mathrm{sn} u$, $\mathrm{cn} u$ and $\mathrm{dn} u$, respectively.
cn
Type: System..::..Double%
On exit: the values of the functions $\mathrm{sn} u$, $\mathrm{cn} u$ and $\mathrm{dn} u$, respectively.
dn
Type: System..::..Double%
On exit: the values of the functions $\mathrm{sn} u$, $\mathrm{cn} u$ and $\mathrm{dn} u$, respectively.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

s21ca 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 usd u=sn u/dn und u=1/dn udc u=dn u/cn unc u=1/cn usc u=sn u/cn uns u=1/sn uds u=dn u/sn ucs u=cn u/sn u$
(see Abramowitz and Stegun (1972)).
s21ca 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.

# 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

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, $\mathrm{abs}\left({\mathbf{u}}\right)>\sqrt{\lambda }$, where $\lambda =1/{\mathbf{x02am}}\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 }$.
${\mathbf{ifail}}=-9000$
An error occured, see message report.

# Accuracy

In principle the method 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.

None.

# Example

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

Example program (C#): s21cae.cs

Example program data: s21cae.d

Example program results: s21cae.r