Mercurial > octave-antonio
annotate scripts/statistics/distributions/chi2rnd.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 |
---|---|
8920 | 1 ## Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007, 2008 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} {} chi2rnd (@var{n}, @var{r}, @var{c}) |
5411 | 21 ## @deftypefnx {Function File} {} chi2rnd (@var{n}, @var{sz}) |
5410 | 22 ## Return an @var{r} by @var{c} or a @code{size (@var{sz})} matrix of |
23 ## random samples from the chisquare distribution with @var{n} degrees | |
24 ## of freedom. @var{n} must be a 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 size of @var{n}. | |
28 ## @end deftypefn | |
29 | |
5428 | 30 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 31 ## Description: Random deviates from the chi-square distribution |
32 | |
5411 | 33 function rnd = chi2rnd (n, r, c) |
5410 | 34 |
35 if (nargin == 3) | |
36 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
|
37 error ("chi2rnd: R must be a positive integer"); |
5410 | 38 endif |
39 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
|
40 error ("chi2rnd: C must be a positive integer"); |
5410 | 41 endif |
42 sz = [r, c]; | |
43 | |
44 if (any (size (n) != 1) | |
10549 | 45 && (length (size (n)) != length (sz) || any (size (n) != 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
|
46 error ("chi2rnd: N must be scalar or of size [R, C]"); |
5410 | 47 endif |
48 elseif (nargin == 2) | |
49 if (isscalar (r) && (r > 0)) | |
50 sz = [r, r]; | |
51 elseif (isvector(r) && all (r > 0)) | |
52 sz = r(:)'; | |
53 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
|
54 error ("chi2rnd: R must be a positive integer or vector"); |
5410 | 55 endif |
56 | |
57 if (any (size (n) != 1) | |
10549 | 58 && (length (size (n)) != length (sz) || any (size (n) != 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
|
59 error ("chi2rnd: N must be scalar or of size SZ"); |
5410 | 60 endif |
61 elseif (nargin == 1) | |
62 sz = size(n); | |
63 else | |
6046 | 64 print_usage (); |
5410 | 65 endif |
66 | |
67 if (isscalar (n)) | |
68 if (find (!(n > 0) | !(n < Inf))) | |
10525
3306cfcb856e
Replace constructs like "NaN * one()" with "NaN()" and "Inf * ones ()" with "Inf()"
David Bateman <dbateman@free.fr>
parents:
8920
diff
changeset
|
69 rnd = NaN (sz); |
5410 | 70 else |
8050
dac919d9c418
chi2rnd.m: fix missing semicolon
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
71 rnd = 2 * randg(n/2, sz); |
5410 | 72 endif |
73 else | |
74 [retval, n, dummy] = common_size (n, ones (sz)); | |
75 if (retval > 0) | |
5411 | 76 error ("chi2rnd: a and b must be of common size or scalar"); |
5410 | 77 endif |
78 | |
79 rnd = zeros (sz); | |
80 k = find (!(n > 0) | !(n < Inf)); | |
81 if (any (k)) | |
82 rnd(k) = NaN; | |
83 endif | |
84 | |
85 k = find ((n > 0) & (n < Inf)); | |
86 if (any (k)) | |
8320
9a05d76e5291
chi2rnd.m: fix missing semicolon
John W. Eaton <jwe@octave.org>
parents:
8050
diff
changeset
|
87 rnd(k) = 2 * randg(n(k)/2, size(k)); |
5410 | 88 endif |
89 endif | |
90 | |
91 endfunction |