Mercurial > octave-nkf
annotate scripts/specfun/betaln.m @ 20595:c1a6c31ac29a
eliminate more simple uses of error_state
* ov-classdef.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Oct 2015 00:20:02 -0400 |
parents | 9fc020886ae9 |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19132
diff
changeset
|
1 ## Copyright (C) 1998-2015 Nicol N. Schraudolph |
5820 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5820 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5820 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Mapping Function} {} betaln (@var{a}, @var{b}) | |
19132 | 21 ## Compute the natural logarithm of the Beta function for real inputs @var{a} |
22 ## and @var{b}. | |
23 ## | |
24 ## @code{betaln} is defined as | |
5820 | 25 ## @tex |
26 ## $$ | |
12659
8673b08a52bf
betaln.m: Improve documentation string, particularly for Tex format.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
27 ## {\rm betaln} (a, b) = \ln (B (a,b)) \equiv \ln ({\Gamma (a) \Gamma (b) \over \Gamma (a + b)}). |
5820 | 28 ## $$ |
29 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
30 ## @ifnottex |
5820 | 31 ## |
32 ## @example | |
12659
8673b08a52bf
betaln.m: Improve documentation string, particularly for Tex format.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
33 ## betaln (a, b) = log (beta (a, b)) |
5820 | 34 ## @end example |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
35 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
36 ## @end ifnottex |
19132 | 37 ## and is calculated in a way to reduce the occurrence of underflow. |
38 ## | |
39 ## The Beta function can grow quite large and it is often more useful to work | |
40 ## with the logarithm of the output rather than the function directly. | |
41 ## @seealso{beta, betainc, betaincinv, gammaln} | |
5820 | 42 ## @end deftypefn |
43 | |
44 ## Author: Nicol N. Schraudolph <nic@idsia.ch> | |
45 ## Created: 06 Aug 1998 | |
46 ## Keywords: log beta special function | |
47 | |
48 function retval = betaln (a, b) | |
12659
8673b08a52bf
betaln.m: Improve documentation string, particularly for Tex format.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
49 |
5820 | 50 if (nargin != 2) |
6046 | 51 print_usage (); |
5820 | 52 endif |
53 | |
19132 | 54 if (! isreal (a) || ! isreal (b)) |
55 error ("betaln: A and B must be real"); | |
56 elseif (! size_equal (a, b) && numel (a) != 1 && numel (b) != 1) | |
57 error ("betaln: A and B must have consistent sizes"); | |
58 endif | |
59 | |
5820 | 60 retval = gammaln (a) + gammaln (b) - gammaln (a + b); |
12659
8673b08a52bf
betaln.m: Improve documentation string, particularly for Tex format.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
61 |
5820 | 62 endfunction |
63 | |
12659
8673b08a52bf
betaln.m: Improve documentation string, particularly for Tex format.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
64 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 %!assert (betaln (3,4), log (beta (3,4)), eps) |
5820 | 66 |
19867
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
67 ## Test input validation |
19132 | 68 %!error betaln () |
69 %!error betaln (1) | |
70 %!error betaln (1,2,3) | |
71 %!error <A and B must be real> betaln (1i, 2) | |
72 %!error <A and B must be real> betaln (2, 1i) | |
73 %!error <A and B must have consistent sizes> betaln ([1 2], [1 2 3]) | |
74 %!error <A and B must have consistent sizes> betaln ([1 2 3], [1 2]) | |
75 %!error <A and B must have consistent sizes> betaln ([1 2 3], [1 2 3]') | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14363
diff
changeset
|
76 |