Mercurial > hg > octave-nkf
annotate scripts/specfun/beta.m @ 9211:f0c3d3fc4903
Simplify Texinfo documentation in .m scripts by removing redundant @iftex calls
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sun, 17 May 2009 14:39:39 -0700 |
parents | eb63fbe60fab |
children | 693e22af08ae |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2005, 2006, |
8920 | 2 ## 2007, 2008, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
1026 | 19 |
3381 | 20 ## -*- texinfo -*- |
3321 | 21 ## @deftypefn {Mapping Function} {} beta (@var{a}, @var{b}) |
7601
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
22 ## For real inputs, return the Beta function, |
3321 | 23 ## @tex |
24 ## $$ | |
25 ## B (a, b) = {\Gamma (a) \Gamma (b) \over \Gamma (a + b)}. | |
26 ## $$ | |
27 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7601
diff
changeset
|
28 ## @ifnottex |
3426 | 29 ## |
3321 | 30 ## @example |
31 ## beta (a, b) = gamma (a) * gamma (b) / gamma (a + b). | |
32 ## @end example | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7601
diff
changeset
|
33 ## @end ifnottex |
3321 | 34 ## @end deftypefn |
2311 | 35 |
5428 | 36 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2312 | 37 ## Created: 13 June 1993 |
38 ## Adapted-By: jwe | |
39 | |
1026 | 40 function retval = beta (a, b) |
2325 | 41 |
1026 | 42 if (nargin != 2) |
6046 | 43 print_usage (); |
1026 | 44 endif |
45 | |
7601
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
46 if (any (size (a) != size (b)) && numel (a) != 1 && numel (b) != 1) |
8664 | 47 error ("beta: inputs have inconsistent sizes"); |
7601
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
48 endif |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
49 |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
50 if (! isreal (a) || ! isreal (b)) |
8664 | 51 error ("beta: inputs must be real"); |
7601
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
52 endif |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
53 |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
54 retval = real (exp (gammaln (a) + gammaln (b) - gammaln (a+b))); |
715 | 55 |
56 endfunction | |
7385 | 57 |
58 %!test | |
59 %! a=[1, 1.5, 2, 3]; | |
60 %! b=[4, 3, 2, 1]; | |
61 %! v1=beta(a,b); | |
62 %! v2=beta(b,a); | |
63 %! v3=gamma(a).*gamma(b)./gamma(a+b); | |
64 %! assert(all(abs(v1-v2)<sqrt(eps)) && all(abs(v2-v3)<sqrt(eps))); | |
65 | |
66 %!error beta(); | |
67 | |
68 %!error beta(1); | |
69 | |
7601
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
70 %!assert (1, beta (1, 1)) |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
71 |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
72 %!test |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
73 %! a = 2:10; |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
74 %! tol = 10 * max (a) * eps; |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
75 %! assert (-a, beta (-1./a, 1), tol) |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
76 %! assert (-a, beta (1, -1./a), tol) |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
77 |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
78 %!test |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
79 %! a = 0.25 + (0:5) * 0.5; |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
80 %! tol = 10 * max (a) * eps; |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
81 %! assert (zeros (size (a)), beta (a, -a), tol) |
8a939b217863
Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents:
7385
diff
changeset
|
82 %! assert (zeros (size (a)), beta (-a, a), tol) |