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} {} unifinv (@var{x}, @var{a}, @var{b}) |
5410
|
21 ## For each element of @var{x}, compute the quantile (the inverse of the |
|
22 ## CDF) at @var{x} of the uniform distribution on [@var{a}, @var{b}]. |
|
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: Quantile function of the uniform distribution |
|
29 |
5411
|
30 function inv = unifinv (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) |
|
44 error ("uniform_cdf: x, a and b must be of common size or scalar"); |
|
45 endif |
|
46 endif |
|
47 |
|
48 sz = size (x); |
|
49 inv = zeros (sz); |
|
50 |
|
51 k = find ((x < 0) | (x > 1) | isnan (x) | !(a < b)); |
|
52 if (any (k)) |
|
53 inv(k) = NaN; |
|
54 endif |
|
55 |
|
56 k = find ((x >= 0) & (x <= 1) & (a < b)); |
|
57 if (any (k)) |
|
58 if (isscalar (a) && isscalar(b)) |
|
59 inv(k) = a + x(k) .* (b - a); |
|
60 else |
|
61 inv(k) = a(k) + x(k) .* (b(k) - a(k)); |
|
62 endif |
|
63 endif |
|
64 |
|
65 endfunction |