3191
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3191
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
3426
|
7 ## |
3191
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
11 ## General Public License for more details. |
|
12 ## |
3191
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
3456
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {} cauchy_rnd (@var{lambda}, @var{sigma}, @var{r}, @var{c}) |
|
19 ## Return an @var{r} by @var{c} matrix of random samples from the Cauchy |
|
20 ## distribution with parameters @var{lambda} and @var{sigma} which must |
|
21 ## both be scalar or of size @var{r} by @var{c}. |
3191
|
22 ## |
3456
|
23 ## If @var{r} and @var{c} are omitted, the size of the result matrix is |
|
24 ## the common size of @var{lambda} and @var{sigma}. |
|
25 ## @end deftypefn |
3426
|
26 |
3456
|
27 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
28 ## Description: Random deviates from the Cauchy distribution |
3191
|
29 |
|
30 function rnd = cauchy_rnd (l, scale, r, c) |
3426
|
31 |
3191
|
32 if (nargin == 4) |
3457
|
33 if (! (is_scalar (r) && (r > 0) && (r == round (r)))) |
3456
|
34 error ("cauchy_rnd: r must be a positive integer"); |
3191
|
35 endif |
3457
|
36 if (! (is_scalar (c) && (c > 0) && (c == round (c)))) |
3456
|
37 error ("cauchy_rnd: c must be a positive integer"); |
3191
|
38 endif |
|
39 [retval, l, scale] = common_size (l, scale, zeros (r, c)); |
|
40 if (retval > 0) |
3456
|
41 error ("cauchy_rnd: lambda and sigma must be scalar or of size %d by %d", |
|
42 r, c); |
3191
|
43 endif |
|
44 elseif (nargin == 2) |
|
45 [retval, l, scale] = common_size (l, scale); |
|
46 if (retval > 0) |
3456
|
47 error ("cauchy_rnd: lambda and sigma must be of common size or scalar"); |
3191
|
48 endif |
|
49 [r, c] = size (l); |
|
50 else |
3456
|
51 usage ("cauchy_rnd (lambda, sigma, r, c)"); |
3191
|
52 endif |
3426
|
53 |
3191
|
54 s = r * c; |
|
55 l = reshape (l, 1, s); |
|
56 scale = reshape (scale, 1, s); |
3426
|
57 |
3191
|
58 rnd = NaN * ones (1, s); |
3426
|
59 |
3191
|
60 k = find ((l > -Inf) & (l < Inf) & (scale > 0) & (scale < Inf)); |
|
61 if (any (k)) |
|
62 rnd(k) = l(k) - cot (pi * rand (1, length (k))) .* scale(k); |
|
63 endif |
|
64 |
|
65 rnd = reshape (rnd, r, c); |
3426
|
66 |
3191
|
67 endfunction |