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_beta_log_real (s14cb)

## Purpose

nag_specfun_beta_log_real (s14cb) returns the value of the logarithm of the beta function, $\mathrm{ln}B\left(a,b\right)$, via the routine name.

## Syntax

[result, ifail] = s14cb(a, b)
[result, ifail] = nag_specfun_beta_log_real(a, b)

## Description

nag_specfun_beta_log_real (s14cb) calculates values for $\mathrm{ln}B\left(a,b\right)$ where $B$ is the beta function given by
 $Ba,b = ∫ 0 1 ta-1 1-t b-1 dt$
or equivalently
 $Ba,b = Γa Γb Γa+b$
and $\Gamma \left(x\right)$ is the gamma function. Note that the beta function is symmetric, so that $B\left(a,b\right)=B\left(b,a\right)$.
In order to efficiently obtain accurate results several methods are used depending on the parameters $a$ and $b$.
Let ${a}_{0}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(a,b\right)$ and ${b}_{0}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(a,b\right)$. Then:
for ${a}_{0}\ge 8$,
 $ln⁡B = 0.5 ln⁡ 2π -0.5 lnb0 + Δa0 + Δ b0 - Δ a0+b0 - u - v ;$
where
• $\Delta \left({a}_{0}\right)=\mathrm{ln}\Gamma \left({a}_{0}\right)-\left({a}_{0}-0.5\right)\mathrm{ln}{a}_{0}+{a}_{0}-0.5\mathrm{ln}\left(2\pi \right)$,
• $u=-\left({a}_{0}-0.5\right)\mathrm{ln}\left[\frac{{a}_{0}}{{a}_{0}+{b}_{0}}\right]$  and
• $v={b}_{0}\mathrm{ln}\left(1+\frac{{a}_{0}}{{b}_{0}}\right)$.
for ${a}_{0}<1$,
• for ${b}_{0}\ge 8$,
 $ln⁡B = ln⁡Γ a0 + ln⁡ Γ b0 Γ a0 + b0 ;$
• for ${b}_{0}<8$,
 $ln⁡B = ln⁡Γ a0 + ln⁡Γ b0 - ln⁡Γ a0 + b0 ;$
for $2<{a}_{0}<8$,  ${a}_{0}$ is reduced to the interval $\left[1,2\right]$ by $B\left(a,b\right)=\frac{{a}_{0}-1}{{a}_{0}+{b}_{0}-1}B\left({a}_{0}-1,{b}_{0}\right)$;
for $1\le {a}_{0}\le 2$,
• for ${b}_{0}\ge 8$,
 $ln⁡B = ln⁡Γ a0 + ln⁡ Γ b0 Γ a0 + b0 ;$
• for $2<{b}_{0}<8$, ${b}_{0}$ is reduced to the interval $\left[1,2\right]$;
• for ${b}_{0}\le 2$,
 $ln⁡B = ln⁡Γ a0 + ln⁡Γ b0 - ln⁡Γ a0 + b0 .$
nag_specfun_beta_log_real (s14cb) is derived from BETALN in DiDonato and Morris (1992).

## References

DiDonato A R and Morris A H (1992) Algorithm 708: Significant digit computation of the incomplete beta function ratios ACM Trans. Math. Software 18 360–373

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{a}$ – double scalar
The argument $a$ of the function.
Constraint: ${\mathbf{a}}>0.0$.
2:     $\mathrm{b}$ – double scalar
The argument $b$ of the function.
Constraint: ${\mathbf{b}}>0.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:
${\mathbf{ifail}}=1$
Constraint: ${\mathbf{a}}>0.0$.
Constraint: ${\mathbf{b}}>0.0$.
${\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

nag_specfun_beta_log_real (s14cb) should produce full relative accuracy for all input arguments.

None.

## Example

This example reads values of the arguments $a$ and $b$ from a file, evaluates the function and prints the results.
```function s14cb_example

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

a = [0.2; 0.4; 0.6; 0.8; 1.0; 1.0; 1.0; 2.0; 3.0; 4.0; ...
5.0; 6.0; 6.0; 6.0; 6.0; 6.0; 7.0];
b = [1.0; 1.0; 1.0; 1.0; 0.2; 0.4; 1.0; 2.0; 3.0; 4.0; ...
5.0; 2.0; 3.0; 4.0; 5.0; 6.0; 7.0];
lb = zeros(numel(a), 1);
for i = 1:numel(a)
[lb(i), ifail] = s14cb(a(i), b(i));
end
fprintf('\n  a    b        ln(beta(a,b))\n');
fprintf('%5.2f%5.2f%17.4e\n', vertcat(a', b', lb'));

```
```s14cb example results

a    b        ln(beta(a,b))
0.20 1.00       1.6094e+00
0.40 1.00       9.1629e-01
0.60 1.00       5.1083e-01
0.80 1.00       2.2314e-01
1.00 0.20       1.6094e+00
1.00 0.40       9.1629e-01
1.00 1.00       0.0000e+00
2.00 2.00      -1.7918e+00
3.00 3.00      -3.4012e+00
4.00 4.00      -4.9416e+00
5.00 5.00      -6.4457e+00
6.00 2.00      -3.7377e+00
6.00 3.00      -5.1240e+00
6.00 4.00      -6.2226e+00
6.00 5.00      -7.1389e+00
6.00 6.00      -7.9273e+00
7.00 7.00      -9.3937e+00
```