Home > wafo > wstats > mvnormpdf.m

mvnormpdf

PURPOSE ^

Multivariate Normal probability density function.

SYNOPSIS ^

pdf = mvnormpdf(X,m,S)

DESCRIPTION ^

 MVNORMPDF Multivariate Normal probability density function.   
  
  CALL: pdf = mvnormpdf(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(mvnormpdf([X1(:),X2(:)]),100,100); 
  [area,epsi] = simpson(x,f); 
  [area2,epsi2] = simpson(x,area); 
  
 See also  wnormpdf

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function pdf = mvnormpdf(X,m,S) 
002 %MVNORMPDF Multivariate Normal probability density function.   
003 % 
004 % CALL: pdf = mvnormpdf(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(mvnormpdf([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  
046 % new and fast call 
047 pdf = exp(-0.5*sum((Xn(:,:)/S).*Xn(:,:) ,2))/den; 
048 return 
049  
050 % old call slow 
051 S1 = inv(S); 
052 for ix=1:n 
053   pdf(ix) = exp(-0.5*Xn(ix,:)*S1*(Xn(ix,:).'))/den; 
054 end 
055

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003