annotate scripts/statistics/distributions/wblinv.m @ 12695:c9e1a2f8d7f8 stable

wblinv.m: Bug fix to return 0 for input 0 and not -Inf. * wblinv.m: Bug fix to return 0 for input 0 and not -Inf.
author Rik <octave@nomad.inbox5.com>
date Tue, 31 May 2011 22:52:18 -0700
parents fd0a3ac60b0e
children 19b9f17d22af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
1 ## Copyright (C) 1995-2011 Kurt Hornik
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
2 ##
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
4 ##
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
9 ##
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
14 ##
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
18
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Function File} {} wblinv (@var{x}, @var{scale}, @var{shape})
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
21 ## Compute the quantile (the inverse of the 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: 10525
diff changeset
22 ## Weibull distribution with scale parameter @var{scale} and shape
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
23 ## parameter @var{shape}.
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
24 ## @end deftypefn
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
25
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
26 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
27 ## Description: Quantile function of the Weibull distribution
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
28
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
29 function inv = wblinv (x, scale, shape)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
30
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
31 if (nargin < 1 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5693
diff changeset
32 print_usage ();
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
33 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
34
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
35 if (nargin < 3)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
36 shape = 1;
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
37 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
38
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
39 if (nargin < 2)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
40 scale = 1;
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
41 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
42
11128
9cb5c0b7b43b Fix reversed documentation for shape and scale parameters in Weibull family of functions.
Rik <octave@nomad.inbox5.com>
parents: 10525
diff changeset
43 if (!isscalar (scale) || !isscalar (shape))
9cb5c0b7b43b Fix reversed documentation for shape and scale parameters in Weibull family of functions.
Rik <octave@nomad.inbox5.com>
parents: 10525
diff changeset
44 [retval, x, scale, shape] = common_size (x, scale, shape);
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
45 if (retval > 0)
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11128
diff changeset
46 error ("wblinv: X, SCALE and SHAPE must be of common size or scalar");
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
47 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
48 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
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
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
51
11128
9cb5c0b7b43b Fix reversed documentation for shape and scale parameters in Weibull family of functions.
Rik <octave@nomad.inbox5.com>
parents: 10525
diff changeset
52 ok = ((scale > 0) & (scale < Inf) & (shape > 0) & (shape < Inf));
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
53
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
54 k = find ((x == 0) & ok);
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
55 if (any (k))
12695
c9e1a2f8d7f8 wblinv.m: Bug fix to return 0 for input 0 and not -Inf.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
56 inv(k) = 0;
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
57 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
58
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
59 k = find ((x > 0) & (x < 1) & ok);
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
60 if (any (k))
11128
9cb5c0b7b43b Fix reversed documentation for shape and scale parameters in Weibull family of functions.
Rik <octave@nomad.inbox5.com>
parents: 10525
diff changeset
61 if (isscalar (scale) && isscalar (shape))
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
62 inv(k) = scale * (- log (1 - x(k))) .^ (1 / shape);
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
63 else
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
64 inv(k) = scale(k) .* (- log (1 - x(k))) .^ (1 ./ shape(k));
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
65 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
66 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
67
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
68 k = find ((x == 1) & ok);
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
69 if (any (k))
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
70 inv(k) = Inf;
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
71 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
72
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
73 endfunction