3191
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3922
|
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 |
3191
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
3426
|
9 ## |
3922
|
10 ## Octave is distributed in the hope that it will be useful, but |
3191
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
13 ## General Public License for more details. |
|
14 ## |
3191
|
15 ## You should have received a copy of the GNU General Public License |
3922
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
3191
|
19 |
3456
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} stdnormal_rnd (@var{r}, @var{c}) |
4854
|
22 ## @deftypefnx {Function File} {} stdnormal_rnd (@var{sz}) |
|
23 ## Return an @var{r} by @var{c} or @code{size (@var{sz})} matrix of |
|
24 ## random numbers from the standard normal distribution. |
3456
|
25 ## @end deftypefn |
3426
|
26 |
3456
|
27 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
28 ## Description: Random deviates from the standard normal distribution |
3191
|
29 |
|
30 function rnd = stdnormal_rnd (r, c) |
3426
|
31 |
4854
|
32 if (nargin != 1 && nargin != 2) |
3191
|
33 usage ("stdnormal_rnd (r, c)"); |
|
34 endif |
|
35 |
4854
|
36 if (nargin == 2) |
|
37 if (! (isscalar (r) && (r > 0) && (r == round (r)))) |
|
38 error ("stdnormal_rnd: r must be a positive integer"); |
|
39 endif |
|
40 if (! (isscalar (c) && (c > 0) && (c == round (c)))) |
|
41 error ("stdnormal_rnd: c must be a positive integer"); |
|
42 endif |
|
43 sz = [r, c]; |
|
44 else |
|
45 if (isscalar (r) && (r > 0)) |
|
46 sz = [r, r]; |
|
47 elseif (isvector(r) && all (r > 0)) |
|
48 sz = r(:)'; |
|
49 else |
|
50 error ("stdnormal_rnd: r must be a postive integer or vector"); |
|
51 endif |
3191
|
52 endif |
|
53 |
4854
|
54 rnd = randn (sz); |
3426
|
55 |
3191
|
56 endfunction |