Mercurial > octave
comparison scripts/statistics/distributions/weibull_inv.m @ 3426:f8dde1807dee
[project @ 2000-01-13 08:40:00 by jwe]
author | jwe |
---|---|
date | Thu, 13 Jan 2000 08:40:53 +0000 |
parents | e4f4b2d26ee9 |
children | 434790acb067 |
comparison
equal
deleted
inserted
replaced
3425:8625164a0a39 | 3426:f8dde1807dee |
---|---|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik | 1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
2 ## | 2 ## |
3 ## This program is free software; you can redistribute it and/or modify | 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 | 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) | 5 ## the Free Software Foundation; either version 2, or (at your option) |
6 ## any later version. | 6 ## any later version. |
7 ## | 7 ## |
8 ## This program is distributed in the hope that it will be useful, but | 8 ## This program is distributed in the hope that it will be useful, but |
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of | 9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 ## General Public License for more details. | 11 ## General Public License for more details. |
12 ## | 12 ## |
13 ## You should have received a copy of the GNU General Public License | 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, | 14 ## along with this file. If not, write to the Free Software Foundation, |
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
16 | 16 |
17 ## usage: weibull_inv (x, lambda, alpha) | 17 ## usage: weibull_inv (x, lambda, alpha) |
18 ## | 18 ## |
19 ## Compute the quantile (the inverse of the CDF) at x of the Weibull | 19 ## Compute the quantile (the inverse of the CDF) at x of the Weibull |
20 ## distribution with shape parameter alpha and scale parameter sigma. | 20 ## distribution with shape parameter alpha and scale parameter sigma. |
21 | 21 |
22 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> | 22 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
23 ## Description: Quantile function of the Weibull distribution | 23 ## Description: Quantile function of the Weibull distribution |
24 | 24 |
25 function inv = weibull_inv (x, shape, scale) | 25 function inv = weibull_inv (x, shape, scale) |
26 | 26 |
27 if (nargin != 3) | 27 if (nargin != 3) |
28 usage ("weibull_inv (x, alpha, sigma)"); | 28 usage ("weibull_inv (x, alpha, sigma)"); |
29 endif | 29 endif |
30 | 30 |
31 [retval, x, shape, scale] = common_size (x, shape, scale); | 31 [retval, x, shape, scale] = common_size (x, shape, scale); |
32 if (retval > 0) | 32 if (retval > 0) |
33 error (["weibull_inv: ", ... | 33 error (["weibull_inv: ", ... |
34 "x, alpha and sigma must be of common size or scalar"]); | 34 "x, alpha and sigma must be of common size or scalar"]); |
35 endif | 35 endif |
36 | 36 |
37 [r, c] = size (x); | 37 [r, c] = size (x); |
38 s = r * c; | 38 s = r * c; |
39 x = reshape (x, 1, s); | 39 x = reshape (x, 1, s); |
40 shape = reshape (shape, 1, s); | 40 shape = reshape (shape, 1, s); |
41 scale = reshape (scale, 1, s); | 41 scale = reshape (scale, 1, s); |
42 | 42 |
43 inv = NaN * ones (1, s); | 43 inv = NaN * ones (1, s); |
44 ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); | 44 ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); |
45 | 45 |
46 k = find ((x == 0) & ok); | 46 k = find ((x == 0) & ok); |
47 if any (k) | 47 if any (k) |
48 inv(k) = -Inf * ones (1, length (k)); | 48 inv(k) = -Inf * ones (1, length (k)); |
49 endif | 49 endif |
50 | 50 |
51 k = find ((x > 0) & (x < 1) & ok); | 51 k = find ((x > 0) & (x < 1) & ok); |
52 if any (k) | 52 if any (k) |
53 inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k)); | 53 inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k)); |
54 endif | 54 endif |
55 | 55 |
56 k = find ((x == 1) & ok); | 56 k = find ((x == 1) & ok); |
57 if any (k) | 57 if any (k) |
58 inv(k) = Inf * ones (1, length (k)); | 58 inv(k) = Inf * ones (1, length (k)); |
59 endif | 59 endif |
60 | 60 |
61 inv = reshape (inv, r, c); | 61 inv = reshape (inv, r, c); |
62 | 62 |
63 endfunction | 63 endfunction |