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_ellipint_legendre_1 (s21be)

## Purpose

nag_specfun_ellipint_legendre_1 (s21be) returns a value of the classical (Legendre) form of the incomplete elliptic integral of the first kind, via the function name.

## Syntax

[result, ifail] = s21be(phi, dm)
[result, ifail] = nag_specfun_ellipint_legendre_1(phi, dm)

## Description

nag_specfun_ellipint_legendre_1 (s21be) calculates an approximation to the integral
 $Fϕ∣m = ∫0ϕ 1-m sin2⁡θ -12 dθ ,$
where $0\le \varphi \le \frac{\pi }{2}$, $m{\mathrm{sin}}^{2}\varphi \le 1$ and $m$ and $\mathrm{sin}\varphi$ may not both equal one.
The integral is computed using the symmetrised elliptic integrals of Carlson (Carlson (1979) and Carlson (1988)). The relevant identity is
 $Fϕ∣m = RF q,r,1 sin⁡ϕ ,$
where $q={\mathrm{cos}}^{2}\varphi$, $r=1-m{\mathrm{sin}}^{2}\varphi$ and ${R}_{F}$ is the Carlson symmetrised incomplete elliptic integral of the first kind (see nag_specfun_ellipint_symm_1 (s21bb)).

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{phi}$ – double scalar
2:     $\mathrm{dm}$ – double scalar
The arguments $\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$.
Note that ${\mathbf{dm}}×{\mathrm{sin}}^{2}\left({\mathbf{phi}}\right)=1.0$ is allowable, as long as ${\mathbf{dm}}\ne 1.0$.

None.

### Output Parameters

1:     $\mathrm{result}$ – double scalar
The result of the function.
2:     $\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:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

${\mathbf{ifail}}=1$
Constraint: $0\le {\mathbf{phi}}\le \frac{\pi }{2}$.
On soft failure, the function returns zero.
${\mathbf{ifail}}=2$
Constraint: ${\mathbf{dm}}×{\mathrm{sin}}^{2}\left({\mathbf{phi}}\right)\le 1.0$.
On soft failure, the function returns zero.
W  ${\mathbf{ifail}}=3$
On entry, $\mathrm{sin}\left({\mathbf{phi}}\right)=1$ and ${\mathbf{dm}}=1.0$; the integral is infinite.
On soft failure, the function returns the largest machine number (see nag_machine_real_largest (x02al)).
${\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 nag_specfun_ellipint_legendre_1 (s21be) 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.

You should consult the S Chapter Introduction, which shows the relationship between this function 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 algorithm used to compute ${R}_{F}$, see the function document for nag_specfun_ellipint_symm_1 (s21bb).
If you wish to input a value of phi outside the range allowed by this function you should refer to Section 17.4 of Abramowitz and Stegun (1972) for useful identities. For example, $F\left(-\varphi |m\right)=-F\left(\varphi |m\right)$ and $F\left(s\pi ±\varphi |m\right)=2sK\left(m\right)±F\left(\varphi |m\right)$ where $s$ is an integer and $K\left(m\right)$ is the complete elliptic integral given by nag_specfun_ellipint_complete_1 (s21bh).
A parameter $m>1$ can be replaced by one less than unity using $F\left(\varphi |m\right)=\frac{1}{\sqrt{m}}F\left(\theta |\frac{1}{m}\right)$, $\mathrm{sin}\theta =\sqrt{m}\mathrm{sin}\varphi$.

## Example

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

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

phi = [pi/6  pi/3   pi/2];
dm  = [1/4   1/2    3/4];
result = phi;

for j = 1:numel(phi)
[result(j), ifail] = s21be(phi(j), dm(j));
end

fprintf('    phi      m        F(phi|m)\n');
fprintf(' %7.2f %7.2f %12.4f\n', [phi; dm; result]);

s21be_plot;

function s21be_plot
phi = [1:0.02:1.56];
m = [0.5:0.02:0.98,0.982:0.002:1];
F = zeros(numel(phi),numel(m));
for i = 1:numel(phi)
for j = 1:numel(m)
[F(i,j), ifail] = s21be(phi(i), m(j));
end
end

fig1 = figure;
[Y,X] = meshgrid(m,phi);
surf(X,Y,F);
xlabel('\Phi');
ylabel('m');
zlabel('F(\Phi,n)');
title({'Incomplete Elliptic Integral of the first kind', ...
'Classical (Legendre) form'});

```
```s21be example results

phi      m        F(phi|m)
0.52    0.25       0.5294
1.05    0.50       1.1424
1.57    0.75       2.1565
```