Mercurial > octave-antonio
annotate scripts/statistics/distributions/gamrnd.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 1740012184f9 |
children | c792872f8942 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 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} {} gamrnd (@var{a}, @var{b}, @var{r}, @var{c}) |
5411 | 21 ## @deftypefnx {Function File} {} gamrnd (@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 Gamma distribution with parameters @var{a} | |
24 ## and @var{b}. Both @var{a} and @var{b} must be scalar or of size | |
25 ## @var{r} by @var{c}. | |
26 ## | |
27 ## If @var{r} and @var{c} are omitted, the size of the result matrix is | |
28 ## the common size of @var{a} and @var{b}. | |
5642 | 29 ## @seealso{gamma, gammaln, gammainc, gampdf, gamcdf, gaminv} |
5410 | 30 ## @end deftypefn |
31 | |
5428 | 32 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 33 ## Description: Random deviates from the Gamma distribution |
34 | |
5411 | 35 function rnd = gamrnd (a, b, r, c) |
5410 | 36 |
37 if (nargin > 1) | |
38 if (!isscalar(a) || !isscalar(b)) | |
39 [retval, a, b] = common_size (a, b); | |
40 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
|
41 error ("gamrnd: A and B must be of common size or scalar"); |
5410 | 42 endif |
43 endif | |
44 endif | |
45 | |
46 if (nargin == 4) | |
47 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
|
48 error ("gamrnd: R must be a positive integer"); |
5410 | 49 endif |
50 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
|
51 error ("gamrnd: C must be a positive integer"); |
5410 | 52 endif |
53 sz = [r, c]; | |
54 | |
55 if (any (size (a) != 1) | |
10549 | 56 && (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
|
57 error ("gamrnd: A and B must be scalar or of size [R, C]"); |
5410 | 58 endif |
59 elseif (nargin == 3) | |
60 if (isscalar (r) && (r > 0)) | |
61 sz = [r, r]; | |
62 elseif (isvector(r) && all (r > 0)) | |
63 sz = r(:)'; | |
64 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
|
65 error ("gamrnd: R must be a positive integer or vector"); |
5410 | 66 endif |
67 | |
68 if (any (size (a) != 1) | |
10549 | 69 && (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
|
70 error ("gamrnd: A and B must be scalar or of size SZ"); |
5410 | 71 endif |
72 elseif (nargin == 2) | |
73 sz = size(a); | |
74 else | |
6046 | 75 print_usage (); |
5410 | 76 endif |
77 | |
78 rnd = zeros (sz); | |
79 | |
80 if (isscalar (a) && isscalar(b)) | |
81 if (find (!(a > 0) | !(a < Inf) | !(b > 0) | !(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
|
82 rnd = NaN (sz); |
5410 | 83 else |
6777 | 84 rnd = b .* randg(a, sz); |
5410 | 85 endif |
86 else | |
87 k = find (!(a > 0) | !(a < Inf) | !(b > 0) | !(b < Inf)); | |
88 if (any (k)) | |
89 rnd(k) = NaN; | |
90 endif | |
91 k = find ((a > 0) & (a < Inf) & (b > 0) & (b < Inf)); | |
92 if (any (k)) | |
6777 | 93 rnd(k) = b(k) .* randg(a(k), size(k)); |
5410 | 94 endif |
95 endif | |
96 | |
97 endfunction |