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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
5411
|
21 ## @deftypefn {Function File} {} normcdf (@var{x}, @var{m}, @var{v}) |
5410
|
22 ## For each element of @var{x}, compute the cumulative distribution |
|
23 ## function (CDF) at @var{x} of the normal distribution with mean |
|
24 ## @var{m} and variance @var{v}. |
|
25 ## |
|
26 ## Default values are @var{m} = 0, @var{v} = 1. |
|
27 ## @end deftypefn |
|
28 |
|
29 ## Author: TT <Teresa.Twaroch@ci.tuwien.ac.at> |
|
30 ## Description: CDF of the normal distribution |
|
31 |
5411
|
32 function cdf = normcdf (x, m, v) |
5410
|
33 |
|
34 if (! ((nargin == 1) || (nargin == 3))) |
6046
|
35 print_usage (); |
5410
|
36 endif |
|
37 |
|
38 if (nargin == 1) |
|
39 m = 0; |
|
40 v = 1; |
|
41 endif |
|
42 |
|
43 if (!isscalar (m) || !isscalar(v)) |
|
44 [retval, x, m, v] = common_size (x, m, v); |
|
45 if (retval > 0) |
5411
|
46 error ("normcdf: x, m and v must be of common size or scalar"); |
5410
|
47 endif |
|
48 endif |
|
49 |
|
50 sz = size (x); |
|
51 cdf = zeros (sz); |
|
52 |
|
53 if (isscalar (m) && isscalar(v)) |
|
54 if (find (isinf (m) | isnan (m) | !(v >= 0) | !(v < Inf))) |
|
55 cdf = NaN * ones (sz); |
|
56 else |
|
57 cdf = stdnormal_cdf ((x - m) ./ sqrt (v)); |
|
58 endif |
|
59 else |
|
60 k = find (isinf (m) | isnan (m) | !(v >= 0) | !(v < Inf)); |
|
61 if (any (k)) |
|
62 cdf(k) = NaN; |
|
63 endif |
|
64 |
|
65 k = find (!isinf (m) & !isnan (m) & (v >= 0) & (v < Inf)); |
|
66 if (any (k)) |
|
67 cdf(k) = stdnormal_cdf ((x(k) - m(k)) ./ sqrt (v(k))); |
|
68 endif |
|
69 endif |
|
70 |
|
71 cdf((v == 0) & (x == m)) = 0.5; |
|
72 |
|
73 endfunction |