1function cdf = normcdf (x, m, s) 2% NORMCDF CDF of the normal distribution 3% CDF = normcdf(X, M, S) computes the cumulative distribution 4% function (CDF) at X of the normal distribution with mean M 5% and standard deviation S. 6% 7% CDF = normcdf(X) is equivalent to CDF = normcdf(X, 0, 1) 8 9% Adapted for Matlab (R) from GNU Octave 3.0.1 10% Original file: statistics/distributions/normcdf.m 11% Original author: TT <Teresa.Twaroch@ci.tuwien.ac.at> 12 13% Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 Kurt Hornik 14% Copyright (C) 2008-2009 Dynare Team 15% 16% This file is part of Dynare. 17% 18% Dynare is free software: you can redistribute it and/or modify 19% it under the terms of the GNU General Public License as published by 20% the Free Software Foundation, either version 3 of the License, or 21% (at your option) any later version. 22% 23% Dynare is distributed in the hope that it will be useful, 24% but WITHOUT ANY WARRANTY; without even the implied warranty of 25% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26% GNU General Public License for more details. 27% 28% You should have received a copy of the GNU General Public License 29% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 30 31if (~ ((nargin == 1) || (nargin == 3))) 32 error ('normcdf: you must give one or three arguments'); 33end 34 35if (nargin == 1) 36 m = 0; 37 s = 1; 38end 39 40if (~isscalar (m) || ~isscalar (s)) 41 [retval, x, m, s] = common_size (x, m, s); 42 if (retval > 0) 43 error ('normcdf: x, m and s must be of common size or scalar'); 44 end 45end 46 47sz = size (x); 48cdf = zeros (sz); 49 50if (isscalar (m) && isscalar(s)) 51 if (find (isinf (m) | isnan (m) | ~(s >= 0) | ~(s < Inf))) 52 cdf = NaN * ones (sz); 53 else 54 cdf = stdnormal_cdf ((x - m) ./ s); 55 end 56else 57 k = find (isinf (m) | isnan (m) | ~(s >= 0) | ~(s < Inf)); 58 if (any (k)) 59 cdf(k) = NaN; 60 end 61 62 k = find (~isinf (m) & ~isnan (m) & (s >= 0) & (s < Inf)); 63 if (any (k)) 64 cdf(k) = stdnormal_cdf ((x(k) - m(k)) ./ s(k)); 65 end 66end 67 68cdf((s == 0) & (x == m)) = 0.5; 69 70end 71