WNORMNDPDF N-Dimensional Normal probability density function. CALL: pdf = wnormndpdf(X,m,S) X = matrix of evaluation points m = mean (default zero vector) S = Covariance matrix (default identity matrix) Example: % Bivariate Gaussian distribution x = linspace(-5,5); [X1 X2] = meshgrid(x); f = reshape(wnormndpdf([X1(:),X2(:)]),100,100); [area,epsi] = simpson(x,f); [area2,epsi2] = simpson(x,area); See also wnormpdf
Determinant. | |
Display message and abort function. | |
Matrix inverse. | |
Write formatted data to string. |
001 function pdf = wnormndpdf(X,m,S) 002 %WNORMNDPDF N-Dimensional Normal probability density function. 003 % 004 % CALL: pdf = wnormndpdf(X,m,S) 005 % 006 % X = matrix of evaluation points 007 % m = mean (default zero vector) 008 % S = Covariance matrix (default identity matrix) 009 % 010 % Example: % Bivariate Gaussian distribution 011 % x = linspace(-5,5); 012 % [X1 X2] = meshgrid(x); 013 % f = reshape(wnormndpdf([X1(:),X2(:)]),100,100); 014 % [area,epsi] = simpson(x,f); 015 % [area2,epsi2] = simpson(x,area); 016 % 017 %See also wnormpdf 018 019 %History 020 % Revised pab 11nov2003 021 % By pab 2002 022 error(nargchk(1,3,nargin)) 023 024 025 [n,d]=size(X); 026 027 if nargin<2|isempty(m), 028 m = zeros(1,d); 029 end 030 if nargin<3|isempty(S), 031 S = eye(d); 032 end 033 if any(d~=size(S)) 034 error(sprintf('Covariance matrix must have %d dimensions',d)) 035 end 036 037 038 039 den = (2*pi*det(S))^(d/2); 040 if den< eps, 041 error('Covariance matrix singular') 042 end 043 Xn = X-m(ones(n,1),:); 044 pdf = zeros(n,1); 045 S1 = inv(S); 046 if 1, % new and fast call 047 pdf = exp(-0.5*sum((Xn(:,:)*S1).*Xn(:,:) ,2))/den; 048 else 049 % old call slow 050 for ix=1:n 051 pdf(ix) = exp(-0.5*Xn(ix,:)*S1*(Xn(ix,:).'))/den; 052 end 053 end
Comments or corrections to the WAFO group