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_complex (s21cb)

## Purpose

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

## Syntax

[sn, cn, dn, ifail] = s21cb(z, ak2)
[sn, cn, dn, ifail] = nag_specfun_jacellip_complex(z, ak2)

## Description

nag_specfun_jacellip_complex (s21cb) 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
 $snz∣k = sin⁡ϕ cnz∣k = cos⁡ϕ dnz∣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
 $snz∣k = k1snkz∣k1 cnz∣k = dnkz∣k1 dnz∣k = cnkz∣k1,$
where ${k}_{1}=1/k$.
Special values include
 $snz∣0 = sin⁡z cnz∣0 = cos⁡z dnz∣0 = 1 snz∣1 = tanh⁡z cnz∣1 = sech⁡z dnz∣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 nag_specfun_jactheta_real (s21cc)).
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 nag_specfun_jacellip_real (s21ca). Further details can be found in Further Comments.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{z}$ – complex scalar
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{x02am}}$.
2:     $\mathrm{ak2}$ – double scalar
The value of ${k}^{2}$.
Constraint: $0.0\le {\mathbf{ak2}}\le 1.0$.

None.

### Output Parameters

1:     $\mathrm{sn}$ – complex scalar
2:     $\mathrm{cn}$ – complex scalar
3:     $\mathrm{dn}$ – complex scalar
The values of the functions $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$, 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, ${\mathbf{ak2}}<0.0$, or ${\mathbf{ak2}}>1.0$, or $\mathrm{abs}\left(\mathrm{Re}\left({\mathbf{z}}\right)\right)>\sqrt{\lambda }$, or $\mathrm{abs}\left(\mathrm{Im}\left({\mathbf{z}}\right)\right)>\sqrt{\lambda }$, where $\lambda =1/{\mathbf{x02am}}$.
${\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.

The values of $\mathrm{sn}z$, $\mathrm{cn}z$ and $\mathrm{dn}z$ are computed via the formulae
 $sn⁡z = snu,kdnv,k′ 1-dn2u,ksn2v,k′ + i cnu,kdnu,ksnv,k′cnv,k′ 1-dn2u,ksn2v,k′ cn⁡z = cnu,kcnv,k′ 1-dn2u,ksn2v,k′ - i snu,kdnu,ksnv,k′dnv,k′ 1-dn2u,ksn2v,k′ dn⁡z = dnu,kcnv,k′dnv,k′ 1-dn2u,ksn2v,k′ - i k2snu,kcnu,ksnv,k′ 1-dn2u,ksn2v,k′ ,$
where $z=u+iv$ and ${k}^{\prime }=\sqrt{1-{k}^{2}}$ (the complementary modulus).

## Example

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.
```function s21cb_example

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

z = -2 +3i;
k = 0.25;

[sn, cn, dn, ifail] = s21cb(z,k);

fprintf(' z = %8.4f%+8.4fi,  k = %7.4f\n\n',real(z), imag(z), k);
fprintf('%16s%23s%23s\n', 'sn(z|k)', 'cn(z|k)', 'dn(z|k)');
fprintf('%10.4f%+10.4fi  %10.4f%+10.4fi  %10.4f%+10.4fi\n', ...
real(sn), imag(sn), real(cn), imag(cn), real(dn), imag(dn));

```
```s21cb example results

z =  -2.0000 +3.0000i,  k =  0.2500

sn(z|k)                cn(z|k)                dn(z|k)
-1.5865   +0.2456i      0.3125   +1.2468i     -0.6395   -0.1523i
```