annotate scripts/specfun/beta.m @ 15144:9cc337ced51a

build: Update OCTAVE_UMFPACK_SEPARATE_SPLIT macro to look for SuiteSparse header file. * acinclude.m4: Update OCTAVE_UMFPACK_SEPARATE_SPLIT macro to look for SuiteSparse header file.
author Rik <rik@octave.org>
date Fri, 10 Aug 2012 12:56:15 -0700
parents 67897baaa05f
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1 ## Copyright (C) 1994-2012 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1026
9fc405c8c06c [project @ 1995-01-11 21:17:01 by jwe]
jwe
parents: 904
diff changeset
18
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3321
diff changeset
19 ## -*- texinfo -*-
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
20 ## @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
21 ## For real inputs, return the Beta function,
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
22 ## @tex
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
23 ## $$
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
24 ## B (a, b) = {\Gamma (a) \Gamma (b) \over \Gamma (a + b)}.
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
25 ## $$
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
26 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7601
diff changeset
27 ## @ifnottex
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
28 ##
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
29 ## @example
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
30 ## beta (a, b) = gamma (a) * gamma (b) / gamma (a + b).
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
31 ## @end example
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9211
diff changeset
32 ##
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7601
diff changeset
33 ## @end ifnottex
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
34 ## @seealso{betaln, betainc}
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2847
diff changeset
35 ## @end deftypefn
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
36
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
37 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
38 ## Created: 13 June 1993
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
39 ## Adapted-By: jwe
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
40
1026
9fc405c8c06c [project @ 1995-01-11 21:17:01 by jwe]
jwe
parents: 904
diff changeset
41 function retval = beta (a, b)
2325
b5568c31ee2c [project @ 1996-07-15 22:20:21 by jwe]
jwe
parents: 2313
diff changeset
42
1026
9fc405c8c06c [project @ 1995-01-11 21:17:01 by jwe]
jwe
parents: 904
diff changeset
43 if (nargin != 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
44 print_usage ();
1026
9fc405c8c06c [project @ 1995-01-11 21:17:01 by jwe]
jwe
parents: 904
diff changeset
45 endif
9fc405c8c06c [project @ 1995-01-11 21:17:01 by jwe]
jwe
parents: 904
diff changeset
46
7601
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
47 if (any (size (a) != size (b)) && numel (a) != 1 && numel (b) != 1)
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9211
diff changeset
48 error ("beta: inputs A and B have inconsistent sizes");
7601
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
49 endif
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
50
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
51 if (! isreal (a) || ! isreal (b))
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 9211
diff changeset
52 error ("beta: inputs A and B must be real");
7601
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
53 endif
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
54
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
55 retval = real (exp (gammaln (a) + gammaln (b) - gammaln (a+b)));
715
6544b83ef9e9 [project @ 1994-09-20 18:40:02 by jwe]
jwe
parents:
diff changeset
56
6544b83ef9e9 [project @ 1994-09-20 18:40:02 by jwe]
jwe
parents:
diff changeset
57 endfunction
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
58
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
60 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 %! a = [1, 1.5, 2, 3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62 %! b = [4, 3, 2, 1];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63 %! v1 = beta (a,b);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
64 %! v2 = beta (b,a);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
65 %! v3 = gamma (a).*gamma (b) ./ gamma (a+b);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
66 %! assert (v1, v2, sqrt (eps));
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
67 %! assert (v2, v3, sqrt (eps));
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
68
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
69 %!assert (beta (1, 1), 1)
7601
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
70
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
71 %!test
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
72 %! a = 2:10;
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
73 %! tol = 10 * max (a) * eps;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
74 %! assert (-a, beta (-1./a, 1), tol);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
75 %! assert (-a, beta (1, -1./a), tol);
7601
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
76
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
77 %!test
8a939b217863 Treat negative values to lgamma and beta correctly
David Bateman <dbateman@free.fr>
parents: 7385
diff changeset
78 %! 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
79 %! tol = 10 * max (a) * eps;
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
80 %! assert (zeros (size (a)), beta (a, -a), tol);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
81 %! assert (zeros (size (a)), beta (-a, a), tol);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
82
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
83 %!error beta ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
84 %!error beta (1)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
85