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