Mercurial > octave-antonio
annotate scripts/statistics/distributions/poissrnd.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 | c776f063fefe |
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 -*- | |
5411 | 20 ## @deftypefn {Function File} {} poissrnd (@var{lambda}, @var{r}, @var{c}) |
5410 | 21 ## Return an @var{r} by @var{c} matrix of random samples from the |
22 ## Poisson distribution with parameter @var{lambda}, which must be a | |
23 ## scalar or of size @var{r} by @var{c}. | |
24 ## | |
25 ## If @var{r} and @var{c} are omitted, the size of the result matrix is | |
26 ## the size of @var{lambda}. | |
27 ## @end deftypefn | |
28 | |
5428 | 29 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410 | 30 ## Description: Random deviates from the Poisson distribution |
31 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
32 function rnd = poissrnd (lambda, r, c) |
5410 | 33 |
34 if (nargin == 3) | |
35 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:
11469
diff
changeset
|
36 error ("poissrnd: R must be a positive integer"); |
5410 | 37 endif |
38 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:
11469
diff
changeset
|
39 error ("poissrnd: C must be a positive integer"); |
5410 | 40 endif |
41 sz = [r, c]; | |
42 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
43 if (any (size (lambda) != 1) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
44 && ((length (size (lambda)) != length (sz)) || any (size (lambda) != 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:
11469
diff
changeset
|
45 error ("poissrnd: LAMBDA must be scalar or of size [R, C]"); |
5410 | 46 endif |
47 elseif (nargin == 2) | |
48 if (isscalar (r) && (r > 0)) | |
49 sz = [r, r]; | |
50 elseif (isvector(r) && all (r > 0)) | |
51 sz = r(:)'; | |
52 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:
11469
diff
changeset
|
53 error ("poissrnd: R must be a positive integer or vector"); |
5410 | 54 endif |
55 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
56 if (any (size (lambda) != 1) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
57 && ((length (size (lambda)) != length (sz)) || any (size (lambda) != 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:
11469
diff
changeset
|
58 error ("poissrnd: LAMBDA must be scalar or of size sz"); |
5410 | 59 endif |
60 elseif (nargin == 1) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
61 sz = size (lambda); |
5410 | 62 else |
6046 | 63 print_usage (); |
5410 | 64 endif |
65 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
66 if (isscalar (lambda)) |
5410 | 67 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
68 if (!(lambda >= 0) || !(lambda < Inf)) |
10525
3306cfcb856e
Replace constructs like "NaN * one()" with "NaN()" and "Inf * ones ()" with "Inf()"
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
69 rnd = NaN (sz); |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
70 elseif (lambda > 0 && lambda < Inf) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
71 rnd = randp(lambda, sz); |
5410 | 72 else |
73 rnd = zeros (sz); | |
74 endif | |
75 else | |
76 rnd = zeros (sz); | |
77 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
78 k = find (!(lambda >= 0) | !(lambda < Inf)); |
5410 | 79 if (any (k)) |
80 rnd(k) = NaN; | |
81 endif | |
82 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
83 k = find ((lambda > 0) & (lambda < Inf)); |
5410 | 84 if (any (k)) |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
11149
diff
changeset
|
85 rnd(k) = randp(lambda(k), size(k)); |
5410 | 86 endif |
87 endif | |
88 | |
89 endfunction |