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, lnB(a,b)$\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 lnB(a,b)$\mathrm{ln}B\left(a,b\right)$ where B$B$ is the beta function given by
 1 B(a,b) = ∫ ta − 1(1 − t)b − 1dt 0
$B(a,b) = ∫ 0 1 ta-1 (1-t) b-1 dt$
or equivalently
 B(a,b) = ( Γ(a) Γ(b) )/(Γ(a + b)) $B(a,b) = Γ(a) Γ(b) Γ(a+b)$
and Γ(x)$\Gamma \left(x\right)$ is the gamma function. Note that the beta function is symmetric, so that B(a,b) = B(b,a)$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$a$ and b$b$.
Let a0 = min (a,b)${a}_{0}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(a,b\right)$ and b0 = max (a,b)${b}_{0}=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(a,b\right)$. Then:
for a08${a}_{0}\ge 8$,
 lnB = 0.5 ln (2π) − 0.5 ln(b0) + Δ(a0) + Δ (b0) − Δ (a0 + b0) − u − v ;
$ln⁡B = 0.5 ln⁡ (2π) -0.5 ln(b0) + Δ(a0) + Δ (b0) - Δ ( a0+b0) - u - v ;$
where
• Δ(a0) = ln Γ(a0) (a00.5) lna0 + a00.5 ln(2π) $\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 = (a00.5) ln[(a0)/( a0 + b0 )] $u=-\left({a}_{0}-0.5\right)\mathrm{ln}\left[\frac{{a}_{0}}{{a}_{0}+{b}_{0}}\right]$  and
• v = b0 ln(1 + (a0)/(b0)) $v={b}_{0}\mathrm{ln}\left(1+\frac{{a}_{0}}{{b}_{0}}\right)$.
for a0 < 1${a}_{0}<1$,
• for b08${b}_{0}\ge 8$,
 lnB = lnΓ (a0) + ln( Γ (b0) )/( Γ (a0 + b0) ) ; $ln⁡B = ln⁡Γ (a0) + ln⁡ Γ (b0) Γ ( a0 + b0 ) ;$
• for b0 < 8${b}_{0}<8$,
 lnB = lnΓ (a0) + lnΓ (b0) − lnΓ (a0 + b0) ; $ln⁡B = ln⁡Γ (a0) + ln⁡Γ (b0) - ln⁡Γ ( a0 + b0 ) ;$
for 2 < a0 < 8$2<{a}_{0}<8$,  a0${a}_{0}$ is reduced to the interval [1,2]$\left[1,2\right]$ by B(a,b) = (a01)/(a0 + b01) B(a01,b0)$B\left(a,b\right)=\frac{{a}_{0}-1}{{a}_{0}+{b}_{0}-1}B\left({a}_{0}-1,{b}_{0}\right)$;
for 1a02$1\le {a}_{0}\le 2$,
• for b08${b}_{0}\ge 8$,
 lnB = lnΓ (a0) + ln( Γ (b0) )/( Γ (a0 + b0) ) ; $ln⁡B = ln⁡Γ (a0) + ln⁡ Γ (b0) Γ ( a0 + b0 ) ;$
• for 2 < b0 < 8$2<{b}_{0}<8$, b0${b}_{0}$ is reduced to the interval [1,2]$\left[1,2\right]$;
• for b02${b}_{0}\le 2$,
 lnB = lnΓ (a0) + lnΓ (b0) − lnΓ (a0 + b0) . $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:     a – double scalar
The argument a$a$ of the function.
Constraint: a > 0.0${\mathbf{a}}>0.0$.
2:     b – double scalar
The argument b$b$ of the function.
Constraint: b > 0.0${\mathbf{b}}>0.0$.

None.

None.

### Output Parameters

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

## Accuracy

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

None.

## Example

```function nag_specfun_beta_log_real_example
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] = nag_specfun_beta_log_real(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'));
```
```

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

```
```function s14cb_example
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'));
```
```

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

```