hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
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)lnB(a,b), 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)lnB(a,b) where BB is the beta function given by
1
B(a,b) = ta1(1t)b1dt
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)Γ(x) is the gamma function. Note that the beta function is symmetric, so that B(a,b) = B(b,a)B(a,b)=B(b,a).
In order to efficiently obtain accurate results several methods are used depending on the parameters aa and bb.
Let a0 = min (a,b)a0=min(a,b) and b0 = max (a,b)b0=max(a,b). Then:
for a08a08,
lnB = 0.5 ln (2π) 0.5 ln(b0) + Δ(a0) + Δ (b0) Δ (a0 + b0) u v ;
lnB = 0.5 ln (2π) -0.5 ln(b0) + Δ(a0) + Δ (b0) - Δ ( a0+b0) - u - v ;
where
for a0 < 1a0<1,
for 2 < a0 < 8 2<a0<8,  a0a0 is reduced to the interval [1,2][1,2] by B(a,b) = (a01)/(a0 + b01) B(a01,b0)B(a,b)=a0-1a0+b0-1 B(a0-1,b0);
for 1a021a02,
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 aa of the function.
Constraint: a > 0.0a>0.0.
2:     b – double scalar
The argument bb of the function.
Constraint: b > 0.0b>0.0.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
Constraint: a > 0.0a>0.0.
Constraint: b > 0.0b>0.0.

Accuracy

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

Further Comments

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


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013