3191
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
|
17 ## usage: weibull_pdf (x, alpha, sigma) |
|
18 ## |
|
19 ## Compute the probability density function (PDF) at x of the Weibull |
|
20 ## distribution with shape parameter alpha and scale parameter sigma |
|
21 ## which is given by |
|
22 ## alpha * sigma^(-alpha) * x^(alpha-1) * exp(-(x/sigma)^alpha) |
|
23 ## for x > 0. |
|
24 |
|
25 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
26 ## Description: PDF of the Weibull distribution |
|
27 |
|
28 function pdf = weibull_pdf (x, shape, scale) |
|
29 |
|
30 if (nargin != 3) |
|
31 usage ("weibull_pdf (x, alpha, sigma)"); |
|
32 endif |
|
33 |
|
34 [retval, x, shape, scale] = common_size (x, shape, scale); |
|
35 if (retval > 0) |
|
36 error (["weibull_pdf: ", ... |
|
37 "x, alpha and sigma must be of common size or scalar"]); |
|
38 endif |
|
39 |
|
40 [r, c] = size (x); |
|
41 s = r * c; |
|
42 x = reshape (x, 1, s); |
|
43 shape = reshape (shape, 1, s); |
|
44 scale = reshape (scale, 1, s); |
|
45 |
|
46 pdf = NaN * ones (1, s); |
|
47 ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); |
|
48 |
|
49 k = find ((x > -Inf) & (x <= 0) & ok); |
|
50 if any (k) |
|
51 pdf(k) = zeros (1, length (k)); |
|
52 endif |
|
53 |
|
54 k = find ((x > 0) & (x < Inf) & ok); |
|
55 if any (k) |
|
56 pdf(k) = (shape(k) .* (scale(k) .^ shape(k)) |
|
57 .* (x(k) .^ (shape(k) - 1)) |
|
58 .* exp(- (x(k) ./ scale(k)) .^ shape(k))); |
|
59 endif |
|
60 |
|
61 pdf = reshape (pdf, r, c); |
|
62 |
|
63 endfunction |