1 function p = normpdf(x,m,s)
2 % NORMPDF returns normal probability density
4 % pdf = normpdf(x,m,s);
6 % Computes the PDF of a the normal distribution
7 % with mean m and standard deviation s
9 % x,m,s must be matrices of same size, or any one can be a scalar.
11 % see also: NORMCDF, NORMINV
15 % $Id: normpdf.m 9033 2011-11-08 20:58:07Z schloegl $
16 % Copyright (C) 2000-2003,2010,2011 by Alois Schloegl <alois.schloegl@gmail.com>
17 % This function is part of the NaN-toolbox
18 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
20 % This program is free software; you can redistribute it and/or modify
21 % it under the terms of the GNU General Public License as published by
22 % the Free Software Foundation; either version 2 of the License, or
23 % (at your option) any later version.
25 % This program is distributed in the hope that it will be useful,
26 % but WITHOUT ANY WARRANTY; without even the implied warranty of
27 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 % GNU General Public License for more details.
30 % You should have received a copy of the GNU General Public License
31 % along with this program; If not, see <http://www.gnu.org/licenses/>.
39 % allocate output memory and check size of argument
40 z = (x-m)./s; % if this line causes an error, input arguments do not fit.
42 %p = ((2*pi)^(-1/2))*exp(-z.^2/2)./s;
43 SQ2PI = 2.5066282746310005024157652848110;
44 p = exp(-z.^2/2)./(s*SQ2PI);
46 p((x==m) & (s==0)) = inf;
50 p(isnan(x) | isnan(m) | isnan(s) | (s<0)) = nan;
52 %!assert(sum(isnan(normpdf([-inf,-2,-1,-.5,0,.5,1,2,3,inf,nan]',2,0))),1)