Home > matlab > missing > stats > normpdf.m

normpdf

PURPOSE ^

NORMPDF PDF of the normal distribution

SYNOPSIS ^

function pdf = normpdf (x, m, s)

DESCRIPTION ^

 NORMPDF  PDF of the normal distribution
  PDF = normpdf(X, M, S) computes the probability density
  function (PDF) at X of the normal distribution with mean M
  and standard deviation S.

  PDF = normpdf(X) is equivalent to PDF = normpdf(X, 0, 1)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pdf = normpdf (x, m, s)
0002 % NORMPDF  PDF of the normal distribution
0003 %  PDF = normpdf(X, M, S) computes the probability density
0004 %  function (PDF) at X of the normal distribution with mean M
0005 %  and standard deviation S.
0006 %
0007 %  PDF = normpdf(X) is equivalent to PDF = normpdf(X, 0, 1)
0008 
0009 % Adapted for Matlab (R) from GNU Octave 3.0.1
0010 % Original file: statistics/distributions/normpdf.m
0011 % Original author: TT <Teresa.Twaroch@ci.tuwien.ac.at>
0012 
0013 % Copyright (C) 1995, 1996, 1997, 2005, 2006, 2007 Kurt Hornik
0014 % Copyright (C) 2008-2009 Dynare Team
0015 %
0016 % This file is part of Dynare.
0017 %
0018 % Dynare is free software: you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published by
0020 % the Free Software Foundation, either version 3 of the License, or
0021 % (at your option) any later version.
0022 %
0023 % Dynare is distributed in the hope that it will be useful,
0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 % GNU General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License
0029 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 if (nargin ~= 1 && nargin ~= 3)
0032     error('normpdf: you must give one or three arguments');
0033 end
0034 
0035 if (nargin == 1)
0036     m = 0;
0037     s = 1;
0038 end
0039 
0040 if (~isscalar (m) || ~isscalar (s))
0041     [retval, x, m, s] = common_size (x, m, s);
0042     if (retval > 0)
0043         error ('normpdf: x, m and s must be of common size or scalars');
0044     end
0045 end
0046 
0047 sz = size (x);
0048 pdf = zeros (sz);
0049 
0050 if (isscalar (m) && isscalar (s))
0051     if (find (isinf (m) | isnan (m) | ~(s >= 0) | ~(s < Inf)))
0052         pdf = NaN * ones (sz);
0053     else
0054         pdf = stdnormal_pdf ((x - m) ./ s) ./ s;
0055     end
0056 else
0057     k = find (isinf (m) | isnan (m) | ~(s >= 0) | ~(s < Inf));
0058     if (any (k))
0059         pdf(k) = NaN;
0060     end
0061 
0062     k = find (~isinf (m) & ~isnan (m) & (s >= 0) & (s < Inf));
0063     if (any (k))
0064         pdf(k) = stdnormal_pdf ((x(k) - m(k)) ./ s(k)) ./ s(k);
0065     end
0066 end
0067 
0068 pdf((s == 0) & (x == m)) = Inf;
0069 pdf((s == 0) & ((x < m) | (x > m))) = 0;
0070 
0071 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005