annotate scripts/statistics/distributions/wblrnd.m @ 11094:add5beb3b845

avoid use of | and & in IF conditions in statistics distribution functions
author John W. Eaton <jwe@octave.org>
date Sat, 09 Oct 2010 11:55:51 -0400
parents be55736a0783
children 9cb5c0b7b43b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9245
16f53d29049f update copyright notices
John W. Eaton <jwe@octave.org>
parents: 9051
diff changeset
1 ## Copyright (C) 1995, 1996, 1997, 2006, 2007, 2009 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: 7007
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: 7007
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: 7007
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: 7007
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 -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
20 ## @deftypefn {Function File} {} wblrnd (@var{scale}, @var{shape}, @var{r}, @var{c})
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
21 ## @deftypefnx {Function File} {} wblrnd (@var{scale}, @var{shape}, @var{sz})
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
22 ## Return an @var{r} by @var{c} matrix of random samples from the
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
23 ## Weibull distribution with parameters @var{scale} and @var{shape}
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 7017
diff changeset
24 ## which must be scalar or of size @var{r} by @var{c}. Or if @var{sz}
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
25 ## is a vector return a matrix of size @var{sz}.
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
26 ##
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
27 ## If @var{r} and @var{c} are omitted, the size of the result matrix is
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
28 ## the common size of @var{alpha} and @var{sigma}.
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
29 ## @end deftypefn
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 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
32 ## Description: Random deviates from the Weibull distribution
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
33
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
34 function rnd = wblrnd (scale, shape, r, c)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
35
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
36 if (nargin > 1)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
37 if (!isscalar(shape) || !isscalar(scale))
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
38 [retval, shape, scale] = common_size (shape, scale);
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
39 if (retval > 0)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10525
diff changeset
40 error ("wblrnd: shape and scale must be of common size or scalar");
5693
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 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
43 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
44
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
45 if (nargin == 4)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
46 if (! (isscalar (r) && (r > 0) && (r == round (r))))
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
47 error ("wblrnd: r must be a positive integer");
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 if (! (isscalar (c) && (c > 0) && (c == round (c))))
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
50 error ("wblrnd: c must be a positive integer");
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
51 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
52 sz = [r, c];
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 if (any (size (scale) != 1) &&
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10525
diff changeset
55 ((length (size (scale)) != length (sz))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10525
diff changeset
56 || any (size (scale) != sz)))
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
57 error ("wblrnd: shape and scale must be scalar or of size [r, c]");
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
58 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
59 elseif (nargin == 3)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
60 if (isscalar (r) && (r > 0))
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
61 sz = [r, r];
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
62 elseif (isvector(r) && all (r > 0))
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
63 sz = r(:)';
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
64 else
7007
6304d9ea0a30 [project @ 2007-10-11 16:26:36 by jwe]
jwe
parents: 6350
diff changeset
65 error ("wblrnd: r must be a positive integer or vector");
5693
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 if (any (size (scale) != 1) &&
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10525
diff changeset
69 ((length (size (scale)) != length (sz))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10525
diff changeset
70 || any (size (scale) != sz)))
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
71 error ("wblrnd: shape and scale must be scalar or of size sz");
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
72 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
73 elseif (nargin == 2)
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
74 sz = size(shape);
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
75 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5693
diff changeset
76 print_usage ();
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
77 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
78
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
79 if (isscalar (shape) && isscalar (scale))
11094
add5beb3b845 avoid use of | and & in IF conditions in statistics distribution functions
John W. Eaton <jwe@octave.org>
parents: 10793
diff changeset
80 if (shape > 0 && shape < Inf && scale > 0 && scale < Inf)
6350
d285f4ee2b0c [project @ 2007-02-23 14:29:19 by dbateman]
dbateman
parents: 6046
diff changeset
81 rnd = scale .* rande(sz) .^ (1./shape);
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
82 else
10525
3306cfcb856e Replace constructs like "NaN * one()" with "NaN()" and "Inf * ones ()" with "Inf()"
David Bateman <dbateman@free.fr>
parents: 9245
diff changeset
83 rnd = NaN (sz);
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
84 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
85 else
6350
d285f4ee2b0c [project @ 2007-02-23 14:29:19 by dbateman]
dbateman
parents: 6046
diff changeset
86 rnd = scale .* rande(sz) .^ (1./shape);
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
87 k = find ((shape <= 0) | (shape == Inf) | ((scale <= 0) & (scale == Inf)));
6350
d285f4ee2b0c [project @ 2007-02-23 14:29:19 by dbateman]
dbateman
parents: 6046
diff changeset
88 if (any(k))
d285f4ee2b0c [project @ 2007-02-23 14:29:19 by dbateman]
dbateman
parents: 6046
diff changeset
89 rnd(k) = NaN;
5693
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
90 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
91 endif
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
92
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
93 endfunction
446b28529300 [project @ 2006-03-17 18:16:03 by jwe]
jwe
parents:
diff changeset
94