# NAG Library Routine Document

## 1Purpose

s21bgf returns a value of the classical (Legendre) form of the incomplete elliptic integral of the third kind, via the function name.

## 2Specification

Fortran Interface
 Function s21bgf ( dn, phi, dm,
 Real (Kind=nag_wp) :: s21bgf Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: dn, phi, dm
#include nagmk26.h
 double s21bgf_ ( const double *dn, const double *phi, const double *dm, Integer *ifail)

## 3Description

s21bgf calculates an approximation to the integral
 $Π n;ϕ∣m = ∫0ϕ 1-n sin2⁡θ -1 1-m sin2⁡θ -12 dθ ,$
where $0\le \varphi \le \frac{\pi }{2}$, $m{\mathrm{sin}}^{2}\varphi \le 1$, $m$ and $\mathrm{sin}\varphi$ may not both equal one, and $n{\mathrm{sin}}^{2}\varphi \ne 1$.
The integral is computed using the symmetrised elliptic integrals of Carlson (Carlson (1979) and Carlson (1988)). The relevant identity is
 $Π n;ϕ∣m = sin⁡ϕ RF q,r,1 + 13 n sin3⁡ϕ RJ q,r,1,s ,$
where $q={\mathrm{cos}}^{2}\varphi$, $r=1-m{\mathrm{sin}}^{2}\varphi$, $s=1-n{\mathrm{sin}}^{2}\varphi$, ${R}_{F}$ is the Carlson symmetrised incomplete elliptic integral of the first kind (see s21bbf) and ${R}_{J}$ is the Carlson symmetrised incomplete elliptic integral of the third kind (see s21bdf).

## 4References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Carlson B C (1979) Computing elliptic integrals by duplication Numerische Mathematik 33 1–16
Carlson B C (1988) A table of elliptic integrals of the third kind Math. Comput. 51 267–280

## 5Arguments

1:     $\mathbf{dn}$ – Real (Kind=nag_wp)Input
2:     $\mathbf{phi}$ – Real (Kind=nag_wp)Input
3:     $\mathbf{dm}$ – Real (Kind=nag_wp)Input
On entry: the arguments $n$, $\varphi$ and $m$ of the function.
Constraints:
• $0.0\le {\mathbf{phi}}\le \frac{\pi }{2}$;
• ${\mathbf{dm}}×{\mathrm{sin}}^{2}\left({\mathbf{phi}}\right)\le 1.0$;
• Only one of $\mathrm{sin}\left({\mathbf{phi}}\right)$ and dm may be $1.0$;
• ${\mathbf{dn}}×{\mathrm{sin}}^{2}\left({\mathbf{phi}}\right)\ne 1.0$.
Note that ${\mathbf{dm}}×{\mathrm{sin}}^{2}\left({\mathbf{phi}}\right)=1.0$ is allowable, as long as ${\mathbf{dm}}\ne 1.0$.
4:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

## 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{phi}}=〈\mathit{\text{value}}〉$.
Constraint: $0\le {\mathbf{phi}}\le \left(\pi /2\right)$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{phi}}=〈\mathit{\text{value}}〉$ and ${\mathbf{dm}}=〈\mathit{\text{value}}〉$; the integral is undefined.
Constraint: ${\mathbf{dm}}×{\mathrm{sin}}^{2}\left({\mathbf{phi}}\right)\le 1.0$.
${\mathbf{ifail}}=3$
On entry, $\mathrm{sin}\left({\mathbf{phi}}\right)=1$ and ${\mathbf{dm}}=1.0$; the integral is infinite.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{phi}}=〈\mathit{\text{value}}〉$ and ${\mathbf{dn}}=〈\mathit{\text{value}}〉$; the integral is infinite.
Constraint: ${\mathbf{dn}}×{\mathrm{sin}}^{2}\left({\mathbf{phi}}\right)\ne 1.0$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

In principle s21bgf is capable of producing full machine precision. However round-off errors in internal arithmetic will result in slight loss of accuracy. This loss should never be excessive as the algorithm does not involve any significant amplification of round-off error. It is reasonable to assume that the result is accurate to within a small multiple of the machine precision.

## 8Parallelism and Performance

s21bgf is not threaded in any implementation.

You should consult the S Chapter Introduction, which shows the relationship between this routine and the Carlson definitions of the elliptic integrals. In particular, the relationship between the argument-constraints for both forms becomes clear.
For more information on the algorithms used to compute ${R}_{F}$ and ${R}_{J}$, see the routine documents for s21bbf and s21bdf, respectively.
If you wish to input a value of phi outside the range allowed by this routine you should refer to Section 17.4 of Abramowitz and Stegun (1972) for useful identities.

## 10Example

This example simply generates a small set of nonextreme arguments that are used with the routine to produce the table of results.

### 10.1Program Text

Program Text (s21bgfe.f90)

None.

### 10.3Program Results

Program Results (s21bgfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017