Mercurial > hg > octave-nkf
annotate scripts/statistics/distributions/wblinv.m @ 10525:3306cfcb856e
Replace constructs like "NaN * one()" with "NaN()" and "Inf * ones ()" with "Inf()"
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 16 Apr 2010 10:32:07 +0200 |
parents | a1dbe9d80eee |
children | 9cb5c0b7b43b |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 2006, 2007 Kurt Hornik |
5693 | 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. | |
5693 | 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/>. | |
5693 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {} wblinv (@var{x}, @var{scale}, @var{shape}) | |
21 ## Compute the quantile (the inverse of the CDF) at @var{x} of the | |
22 ## Weibull distribution with shape parameter @var{scale} and scale | |
23 ## parameter @var{shape}. | |
24 ## @end deftypefn | |
25 | |
26 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> | |
27 ## Description: Quantile function of the Weibull distribution | |
28 | |
29 function inv = wblinv (x, scale, shape) | |
30 | |
31 if (nargin < 1 || nargin > 3) | |
6046 | 32 print_usage (); |
5693 | 33 endif |
34 | |
35 if (nargin < 3) | |
36 shape = 1; | |
37 endif | |
38 | |
39 if (nargin < 2) | |
40 scale = 1; | |
41 endif | |
42 | |
43 if (!isscalar (shape) || !isscalar (scale)) | |
44 [retval, x, shape, scale] = common_size (x, shape, scale); | |
45 if (retval > 0) | |
46 error ("wblinv: x, scale and shape must be of common size or scalar"); | |
47 endif | |
48 endif | |
49 | |
10525
3306cfcb856e
Replace constructs like "NaN * one()" with "NaN()" and "Inf * ones ()" with "Inf()"
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
50 inv = NaN (size (x)); |
5693 | 51 |
52 ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); | |
53 | |
54 k = find ((x == 0) & ok); | |
55 if (any (k)) | |
56 inv(k) = -Inf; | |
57 endif | |
58 | |
59 k = find ((x > 0) & (x < 1) & ok); | |
60 if (any (k)) | |
61 if (isscalar (shape) && isscalar (scale)) | |
62 inv(k) = scale * (- log (1 - x(k))) .^ (1 / shape); | |
63 else | |
64 inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k)); | |
65 endif | |
66 endif | |
67 | |
68 k = find ((x == 1) & ok); | |
69 if (any (k)) | |
70 inv(k) = Inf; | |
71 endif | |
72 | |
73 endfunction |