function y = EgaussD(mu, covar, x)
% Evaluate a Gaussian distribution. 

[n, d] = size(x);
[j, k] = size(covar);
if ((j ~= d) | (k ~=d))
  error('Dimension Error.');
end   
invcov = inv(covar);
mu = reshape(mu, 1, d);    
x = x - ones(n, 1)*mu;
fact = sum(((x*invcov).*x), 2);
y = exp(-0.5*fact);
y = y./sqrt((2*pi)^d*det(covar));


% "Complex and Chaotic Nonlinear Dynamics. 
% Advances in Economics and Finance, 
% Mathematics and Statistics" 
% T.Vialar, Springer 2009.
% Copyright(c) 