Mercurial > octave-antonio
annotate scripts/statistics/distributions/unifrnd.m @ 11472:1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 21:33:04 -0800 |
parents | be55736a0783 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 Kurt Hornik |
5410 | 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. | |
5410 | 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/>. | |
5410 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} unifrnd (@var{a}, @var{b}, @var{r}, @var{c}) |
5411 | 21 ## @deftypefnx {Function File} {} unifrnd (@var{a}, @var{b}, @var{sz}) |
5410 | 22 ## Return an @var{r} by @var{c} or a @code{size (@var{sz})} matrix of |
23 ## random samples from the uniform distribution on [@var{a}, @var{b}]. | |
24 ## Both @var{a} and @var{b} must be scalar or of size @var{r} by @var{c}. | |
25 ## | |
26 ## If @var{r} and @var{c} are omitted, the size of the result matrix is | |
27 ## the common size of @var{a} and @var{b}. | |
28 ## @end deftypefn | |
29 | |
5428 | 30 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 31 ## Description: Random deviates from the uniform distribution |
32 | |
5411 | 33 function rnd = unifrnd (a, b, r, c) |
5410 | 34 |
35 if (nargin > 1) | |
36 if (!isscalar(a) || !isscalar(b)) | |
37 [retval, a, b] = common_size (a, b); | |
38 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:
10793
diff
changeset
|
39 error ("unifrnd: A and B must be of common size or scalar"); |
5410 | 40 endif |
41 endif | |
42 endif | |
43 | |
44 if (nargin == 4) | |
45 if (! (isscalar (r) && (r > 0) && (r == round (r)))) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
46 error ("unifrnd: R must be a positive integer"); |
5410 | 47 endif |
48 if (! (isscalar (c) && (c > 0) && (c == round (c)))) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
49 error ("unifrnd: C must be a positive integer"); |
5410 | 50 endif |
51 sz = [r, c]; | |
52 | |
53 if (any (size (a) != 1) | |
10549 | 54 && (length (size (a)) != length (sz) || any (size (a) != sz))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
55 error ("unifrnd: A and B must be scalar or of size [R, C]"); |
5410 | 56 endif |
57 elseif (nargin == 3) | |
58 if (isscalar (r) && (r > 0)) | |
59 sz = [r, r]; | |
60 elseif (isvector(r) && all (r > 0)) | |
61 sz = r(:)'; | |
62 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
63 error ("unifrnd: R must be a positive integer or vector"); |
5410 | 64 endif |
65 | |
66 if (any (size (a) != 1) | |
10549 | 67 && (length (size (a)) != length (sz) || any (size (a) != sz))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
68 error ("unifrnd: A and B must be scalar or of size SZ"); |
5410 | 69 endif |
70 elseif (nargin == 2) | |
71 sz = size(a); | |
72 else | |
6046 | 73 print_usage (); |
5410 | 74 endif |
75 | |
76 if (isscalar(a) && isscalar(b)) | |
77 if (find (!(-Inf < a) | !(a < b) | !(b < Inf))) | |
10525
3306cfcb856e
Replace constructs like "NaN * one()" with "NaN()" and "Inf * ones ()" with "Inf()"
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
78 rnd = NaN(sz); |
5410 | 79 else |
80 rnd = a + (b - a) .* rand (sz); | |
81 endif | |
82 else | |
83 rnd = a + (b - a) .* rand (sz); | |
84 | |
85 k = find (!(-Inf < a) | !(a < b) | !(b < Inf)); | |
86 if (any (k)) | |
87 rnd(k) = NaN; | |
88 endif | |
89 endif | |
90 | |
91 endfunction |