5410
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
|
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} {} unifcdf (@var{x}, @var{a}, @var{b}) |
5410
|
21 ## Return the CDF at @var{x} of the uniform distribution on [@var{a}, |
|
22 ## @var{b}], i.e., PROB (uniform (@var{a}, @var{b}) <= x). |
|
23 ## |
|
24 ## Default values are @var{a} = 0, @var{b} = 1. |
|
25 ## @end deftypefn |
|
26 |
5428
|
27 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
5410
|
28 ## Description: CDF of the uniform distribution |
|
29 |
5411
|
30 function cdf = unifcdf (x, a, b) |
5410
|
31 |
|
32 if (nargin != 1 && nargin != 3) |
6046
|
33 print_usage (); |
5410
|
34 endif |
|
35 |
|
36 if (nargin == 1) |
|
37 a = 0; |
|
38 b = 1; |
|
39 endif |
|
40 |
|
41 if (!isscalar (a) || !isscalar(b)) |
|
42 [retval, x, a, b] = common_size (x, a, b); |
|
43 if (retval > 0) |
5411
|
44 error ("unifcdf: x, a and b must be of common size or scalar"); |
5410
|
45 endif |
|
46 endif |
|
47 |
|
48 sz = size (x); |
|
49 cdf = zeros (sz); |
|
50 |
|
51 k = find (isnan (x) | !(a < b)); |
|
52 if (any (k)) |
|
53 cdf(k) = NaN; |
|
54 endif |
|
55 |
|
56 k = find ((x >= b) & (a < b)); |
|
57 if (any (k)) |
|
58 cdf(k) = 1; |
|
59 endif |
|
60 |
|
61 k = find ((x > a) & (x < b)); |
|
62 if (any (k)) |
|
63 if (isscalar (a) && isscalar(b)) |
|
64 cdf(k) = (x(k) < b) .* (x(k) - a) ./ (b - a); |
|
65 else |
|
66 cdf(k) = (x(k) < b(k)) .* (x(k) - a(k)) ./ (b(k) - a(k)); |
|
67 endif |
|
68 endif |
|
69 |
|
70 endfunction |