7017
|
1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 Kurt Hornik |
5410
|
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. |
5410
|
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/>. |
5410
|
18 |
|
19 ## -*- texinfo -*- |
5411
|
20 ## @deftypefn {Function File} {} betapdf (@var{x}, @var{a}, @var{b}) |
5410
|
21 ## For each element of @var{x}, returns the PDF at @var{x} of the beta |
|
22 ## distribution with parameters @var{a} and @var{b}. |
|
23 ## @end deftypefn |
|
24 |
5428
|
25 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410
|
26 ## Description: PDF of the Beta distribution |
|
27 |
5411
|
28 function pdf = betapdf (x, a, b) |
5410
|
29 |
|
30 if (nargin != 3) |
6046
|
31 print_usage (); |
5410
|
32 endif |
|
33 |
|
34 if (!isscalar (a) || !isscalar(b)) |
|
35 [retval, x, a, b] = common_size (x, a, b); |
|
36 if (retval > 0) |
5411
|
37 error ("betapdf: x, a and b must be of common size or scalar"); |
5410
|
38 endif |
|
39 endif |
|
40 |
|
41 sz = size (x); |
|
42 pdf = zeros (sz); |
|
43 |
|
44 k = find (!(a > 0) | !(b > 0) | isnan (x)); |
|
45 if (any (k)) |
|
46 pdf (k) = NaN; |
|
47 endif |
|
48 |
|
49 k = find ((x > 0) & (x < 1) & (a > 0) & (b > 0)); |
|
50 if (any (k)) |
|
51 if (isscalar(a) && isscalar(b)) |
|
52 pdf(k) = exp ((a - 1) .* log (x(k)) |
|
53 + (b - 1) .* log (1 - x(k))) ./ beta (a, b); |
|
54 else |
|
55 pdf(k) = exp ((a(k) - 1) .* log (x(k)) |
|
56 + (b(k) - 1) .* log (1 - x(k))) ./ beta (a(k), b(k)); |
|
57 endif |
|
58 endif |
|
59 |
|
60 endfunction |