comparison scripts/statistics/distributions/gamrnd.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children 19b9f17d22af
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} gamrnd (@var{a}, @var{b}, @var{r}, @var{c}) 20 ## @deftypefn {Function File} {} gamrnd (@var{a}, @var{b}, @var{r}, @var{c})
21 ## @deftypefnx {Function File} {} gamrnd (@var{a}, @var{b}, @var{sz}) 21 ## @deftypefnx {Function File} {} gamrnd (@var{a}, @var{b}, @var{sz})
22 ## Return an @var{r} by @var{c} or a @code{size (@var{sz})} matrix of 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} 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 24 ## and @var{b}. Both @var{a} and @var{b} must be scalar or of size
25 ## @var{r} by @var{c}. 25 ## @var{r} by @var{c}.
26 ## 26 ##
27 ## If @var{r} and @var{c} are omitted, the size of the result matrix is 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}. 28 ## the common size of @var{a} and @var{b}.
29 ## @seealso{gamma, gammaln, gammainc, gampdf, gamcdf, gaminv} 29 ## @seealso{gamma, gammaln, gammainc, gampdf, gamcdf, gaminv}
33 ## Description: Random deviates from the Gamma distribution 33 ## Description: Random deviates from the Gamma distribution
34 34
35 function rnd = gamrnd (a, b, r, c) 35 function rnd = gamrnd (a, b, r, c)
36 36
37 if (nargin > 1) 37 if (nargin > 1)
38 if (!isscalar(a) || !isscalar(b)) 38 if (!isscalar(a) || !isscalar(b))
39 [retval, a, b] = common_size (a, b); 39 [retval, a, b] = common_size (a, b);
40 if (retval > 0) 40 if (retval > 0)
41 error ("gamrnd: A and B must be of common size or scalar"); 41 error ("gamrnd: A and B must be of common size or scalar");
42 endif 42 endif
43 endif 43 endif
81 if (find (!(a > 0) | !(a < Inf) | !(b > 0) | !(b < Inf))) 81 if (find (!(a > 0) | !(a < Inf) | !(b > 0) | !(b < Inf)))
82 rnd = NaN (sz); 82 rnd = NaN (sz);
83 else 83 else
84 rnd = b .* randg(a, sz); 84 rnd = b .* randg(a, sz);
85 endif 85 endif
86 else 86 else
87 k = find (!(a > 0) | !(a < Inf) | !(b > 0) | !(b < Inf)); 87 k = find (!(a > 0) | !(a < Inf) | !(b > 0) | !(b < Inf));
88 if (any (k)) 88 if (any (k))
89 rnd(k) = NaN; 89 rnd(k) = NaN;
90 endif 90 endif
91 k = find ((a > 0) & (a < Inf) & (b > 0) & (b < Inf)); 91 k = find ((a > 0) & (a < Inf) & (b > 0) & (b < Inf));