]> Creatis software - CreaPhase.git/blob - octave_packages/m/specfun/betaln.m
update packages
[CreaPhase.git] / octave_packages / m / specfun / betaln.m
1 ## Copyright (C) 1998-2012 Nicol N. Schraudolph
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Mapping Function} {} betaln (@var{a}, @var{b})
21 ## Return the natural logarithm of the Beta function,
22 ## @tex
23 ## $$
24 ##  {\rm betaln} (a, b) = \ln (B (a,b)) \equiv \ln ({\Gamma (a) \Gamma (b) \over \Gamma (a + b)}).
25 ## $$
26 ## @end tex
27 ## @ifnottex
28 ##
29 ## @example
30 ## betaln (a, b) = log (beta (a, b))
31 ## @end example
32 ##
33 ## @end ifnottex
34 ## calculated in a way to reduce the occurrence of underflow.
35 ## @seealso{beta, betainc, gammaln}
36 ## @end deftypefn
37
38 ## Author:   Nicol N. Schraudolph <nic@idsia.ch>
39 ## Created:  06 Aug 1998
40 ## Keywords: log beta special function
41
42 function retval = betaln (a, b)
43
44   if (nargin != 2)
45     print_usage ();
46   endif
47
48   retval = gammaln (a) + gammaln (b) - gammaln (a + b);
49
50 endfunction
51
52
53 %!assert (betaln (3,4), log (beta(3,4)),eps);
54
55 %% Test input validation
56 %!error (betaln (1))
57 %!error (betaln (1,2,3))