Mercurial > hg > octave-lyh
annotate scripts/statistics/distributions/unifcdf.m @ 12749:e7cc2d4a6db3 stable
Fix range of sigma in normal distribution to exclude 0.
* normcdf.m, normpdf.m: Correct 's >= 0' to 's > 0'.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 16 Jun 2011 21:05:10 -0700 |
parents | c792872f8942 |
children | 19b9f17d22af |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 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} {} unifcdf (@var{x}, @var{a}, @var{b}) |
5410 | 21 ## Return the CDF at @var{x} of the uniform distribution on [@var{a}, |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
22 ## @var{b}], i.e., PROB (uniform (@var{a}, @var{b}) @leq{} x). |
5410 | 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) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
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 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
60 |
5410 | 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 |