Mercurial > octave-nkf
annotate scripts/statistics/distributions/wblcdf.m @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | 19b9f17d22af |
children | f3d52523cde1 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13171
diff
changeset
|
1 ## Copyright (C) 2012 Rik Wehbring |
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13171
diff
changeset
|
2 ## Copyright (C) 1995-2012 Kurt Hornik |
5693 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5693 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5693 | 19 |
20 ## -*- texinfo -*- | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## @deftypefn {Function File} {} wblcdf (@var{x}) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 ## @deftypefnx {Function File} {} wblcdf (@var{x}, @var{scale}) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 ## @deftypefnx {Function File} {} wblcdf (@var{x}, @var{scale}, @var{shape}) |
5693 | 24 ## Compute the cumulative distribution function (CDF) at @var{x} of the |
11128
9cb5c0b7b43b
Fix reversed documentation for shape and scale parameters in Weibull family of functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
25 ## Weibull distribution with scale parameter @var{scale} and shape |
5693 | 26 ## parameter @var{shape}, which is |
6754 | 27 ## @tex |
11128
9cb5c0b7b43b
Fix reversed documentation for shape and scale parameters in Weibull family of functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
28 ## $$ 1 - e^{-({x \over scale})^{shape}} $$ |
9cb5c0b7b43b
Fix reversed documentation for shape and scale parameters in Weibull family of functions.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
29 ## for $x \geq 0$. |
6754 | 30 ## @end tex |
31 ## @ifnottex | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
32 ## |
5693 | 33 ## @example |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
34 ## 1 - exp (-(x/scale)^shape) |
5693 | 35 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
36 ## |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
37 ## @noindent |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10525
diff
changeset
|
38 ## for @var{x} @geq{} 0. |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
39 ## |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 ## Default values are @var{scale} = 1, @var{shape} = 1. |
6754 | 41 ## @end ifnottex |
5693 | 42 ## @end deftypefn |
43 | |
44 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> | |
45 ## Description: CDF of the Weibull distribution | |
46 | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
47 function cdf = wblcdf (x, scale = 1, shape = 1) |
5693 | 48 |
49 if (nargin < 1 || nargin > 3) | |
6046 | 50 print_usage (); |
5693 | 51 endif |
52 | |
53 if (!isscalar (shape) || !isscalar (scale)) | |
54 [retval, x, shape, scale] = common_size (x, shape, scale); | |
55 if (retval > 0) | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
56 error ("wblcdf: X, SCALE, and SHAPE must be of common size or scalars"); |
5693 | 57 endif |
58 endif | |
59 | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
60 if (iscomplex (x) || iscomplex (scale) || iscomplex (shape)) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
61 error ("wblcdf: X, SCALE, and SHAPE must not be complex"); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
62 endif |
5693 | 63 |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
64 if (isa (x, "single") || isa (scale, "single") || isa (shape, "single")) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
65 cdf = NaN (size (x), "single"); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
66 else |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
67 cdf = NaN (size (x)); |
5693 | 68 endif |
69 | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
70 ok = (shape > 0) & (shape < Inf) & (scale > 0) & (scale < Inf); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
71 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
72 k = (x <= 0) & ok; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
73 cdf(k) = 0; |
5693 | 74 |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
75 k = (x == Inf) & ok; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
76 cdf(k) = 1; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
77 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
78 k = (x > 0) & (x < Inf) & ok; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
79 if (isscalar (shape) && isscalar (scale)) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
80 cdf(k) = 1 - exp (- (x(k) / scale) .^ shape); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
81 else |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
82 cdf(k) = 1 - exp (- (x(k) ./ scale(k)) .^ shape(k)); |
5693 | 83 endif |
84 | |
85 endfunction | |
13171
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
86 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
87 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
88 %!shared x,y |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
89 %! x = [-1 0 0.5 1 Inf]; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
90 %! y = [0, 1-exp(-x(2:4)), 1]; |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
91 %!assert(wblcdf (x, ones(1,5), ones(1,5)), y); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
92 %!assert(wblcdf (x, 1, ones(1,5)), y); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
93 %!assert(wblcdf (x, ones(1,5), 1), y); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
94 %!assert(wblcdf (x, [0 1 NaN Inf 1], 1), [NaN 0 NaN NaN 1]); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
95 %!assert(wblcdf (x, 1, [0 1 NaN Inf 1]), [NaN 0 NaN NaN 1]); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
96 %!assert(wblcdf ([x(1:2) NaN x(4:5)], 1, 1), [y(1:2) NaN y(4:5)]); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
97 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
98 %% Test class of input preserved |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
99 %!assert(wblcdf ([x, NaN], 1, 1), [y, NaN]); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
100 %!assert(wblcdf (single([x, NaN]), 1, 1), single([y, NaN])); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
101 %!assert(wblcdf ([x, NaN], single(1), 1), single([y, NaN])); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
102 %!assert(wblcdf ([x, NaN], 1, single(1)), single([y, NaN])); |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
103 |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
104 %% Test input validation |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
105 %!error wblcdf () |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
106 %!error wblcdf (1,2,3,4) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
107 %!error wblcdf (ones(3),ones(2),ones(2)) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
108 %!error wblcdf (ones(2),ones(3),ones(2)) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
109 %!error wblcdf (ones(2),ones(2),ones(3)) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
110 %!error wblcdf (i, 2, 2) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
111 %!error wblcdf (2, i, 2) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
112 %!error wblcdf (2, 2, i) |
19b9f17d22af
Overhaul of statistical distribution functions
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
113 |