Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_specfun_jacellip_real (s21ca)

## Purpose

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

## Syntax

[sn, cn, dn, ifail] = s21ca(u, m)
[sn, cn, dn, ifail] = nag_specfun_jacellip_real(u, m)

## Description

nag_specfun_jacellip_real (s21ca) evaluates the Jacobian elliptic functions of argument $u$ and argument $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 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)).
nag_specfun_jacellip_real (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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{u}$ – double scalar
2:     $\mathrm{m}$ – double scalar
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{x02am}}$;
• if $\mathrm{abs}\left({\mathbf{u}}\right)<1/\sqrt{\lambda }$, $\mathrm{abs}\left({\mathbf{m}}\right)\le \sqrt{\lambda }$.

None.

### Output Parameters

1:     $\mathrm{sn}$ – double scalar
2:     $\mathrm{cn}$ – double scalar
3:     $\mathrm{dn}$ – double scalar
The values of the functions $\mathrm{sn}u$, $\mathrm{cn}u$ and $\mathrm{dn}u$, respectively.
4:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\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}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

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

## Example

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

fprintf('s21ca example results\n\n');

u = [0.2   5  -0.5   10];
m = [0.3  -1  -0.1   11];
sn = u; cn = u; dn = u;

for j=1:numel(u)
[sn(j), cn(j), dn(j), ifail] = s21ca(u(j),m(j));
end

disp('       u         m         sn        cn        dn');
fprintf('%10.2f%10.2f%10.4f%10.4f%10.4f\n',[u; m; sn; cn; dn]);

s21ca example results

u         m         sn        cn        dn
0.20      0.30    0.1983    0.9801    0.9941
5.00     -1.00   -0.2440    0.9698    1.0293
-0.50     -0.10   -0.4812    0.8766    1.0115
10.00     11.00    0.2512    0.9679    0.5528