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} {} wblcdf (@var{x}, @var{scale}, @var{shape}) |
|
21 ## Compute the cumulative distribution function (CDF) at @var{x} of the |
|
22 ## Weibull distribution with shape parameter @var{scale} and scale |
|
23 ## parameter @var{shape}, which is |
|
24 ## |
6754
|
25 ## @iftex |
|
26 ## @tex |
|
27 ## $$ 1 - \exp(-(x/shape)^{scale}) $$ |
|
28 ## for $x\geq 0$. |
|
29 ## @end tex |
|
30 ## @end iftex |
|
31 ## @ifnottex |
5693
|
32 ## @example |
|
33 ## 1 - exp(-(x/shape)^scale) |
|
34 ## @end example |
|
35 ## for @var{x} >= 0. |
6754
|
36 ## @end ifnottex |
5693
|
37 ## @end deftypefn |
|
38 |
|
39 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
|
40 ## Description: CDF of the Weibull distribution |
|
41 |
|
42 function cdf = wblcdf (x, scale, shape) |
|
43 |
|
44 if (nargin < 1 || nargin > 3) |
6046
|
45 print_usage (); |
5693
|
46 endif |
|
47 |
|
48 if (nargin < 3) |
|
49 shape = 1; |
|
50 endif |
|
51 |
|
52 if (nargin < 2) |
|
53 scale = 1; |
|
54 endif |
|
55 |
|
56 if (!isscalar (shape) || !isscalar (scale)) |
|
57 [retval, x, shape, scale] = common_size (x, shape, scale); |
|
58 if (retval > 0) |
|
59 error ("wblcdf: x, scale and shape must be of common size or scalar"); |
|
60 endif |
|
61 endif |
|
62 |
|
63 cdf = NaN * ones (size (x)); |
|
64 |
|
65 ok = ((shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf)); |
|
66 |
|
67 k = find ((x <= 0) & ok); |
|
68 if (any (k)) |
|
69 cdf(k) = 0; |
|
70 endif |
|
71 |
|
72 k = find ((x > 0) & (x < Inf) & ok); |
|
73 if (any (k)) |
|
74 if (isscalar (shape) && isscalar (scale)) |
|
75 cdf(k) = 1 - exp (- (x(k) / scale) .^ shape); |
|
76 else |
|
77 cdf(k) = 1 - exp (- (x(k) ./ scale(k)) .^ shape(k)); |
|
78 endif |
|
79 endif |
|
80 |
|
81 k = find ((x == Inf) & ok); |
|
82 if (any (k)) |
|
83 cdf(k) = 1; |
|
84 endif |
|
85 |
|
86 endfunction |