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} {} weibinv (@var{x}, @var{lambda}, @var{alpha}) |
5410
|
22 ## Compute the quantile (the inverse of the CDF) at @var{x} of the |
|
23 ## Weibull distribution with shape parameter @var{alpha} and scale |
|
24 ## parameter @var{sigma}. |
|
25 ## @end deftypefn |
|
26 |
|
27 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
28 ## Description: Quantile function of the Weibull distribution |
|
29 |
5411
|
30 function inv = weibinv (x, shape, scale) |
5410
|
31 |
|
32 if (nargin != 3) |
5411
|
33 usage ("weibinv (x, alpha, sigma)"); |
5410
|
34 endif |
|
35 |
|
36 if (!isscalar (shape) || !isscalar (scale)) |
|
37 [retval, x, shape, scale] = common_size (x, shape, scale); |
|
38 if (retval > 0) |
5411
|
39 error ("weibinv: x, alpha and sigma must be of common size or scalar"); |
5410
|
40 endif |
|
41 endif |
|
42 |
|
43 inv = NaN * ones (size (x)); |
|
44 |
|
45 ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); |
|
46 |
|
47 k = find ((x == 0) & ok); |
|
48 if (any (k)) |
|
49 inv(k) = -Inf; |
|
50 endif |
|
51 |
|
52 k = find ((x > 0) & (x < 1) & ok); |
|
53 if (any (k)) |
|
54 if (isscalar (shape) && isscalar (scale)) |
|
55 inv(k) = scale * (- log (1 - x(k))) .^ (1 / shape); |
|
56 else |
|
57 inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k)); |
|
58 endif |
|
59 endif |
|
60 |
|
61 k = find ((x == 1) & ok); |
|
62 if (any (k)) |
|
63 inv(k) = Inf; |
|
64 endif |
|
65 |
|
66 endfunction |