% FUNCTION Y = LOG10_MVNPDF(X, [MU], [SIGMA])
%
%   X & MU: vectors of same size
%   sigma: square matrix
%
%   default MU = zeros(size(X))
%           SIGMA = diag(ones(size(X)));

function y = log10_mvnpdf(x,mu,sigma)

if nargin < 2
  mu = zeros(size(x));
end

if nargin < 3
  sigma = diag(ones(size(x)));
end

x = x(:);   % Column vector
mu = mu(:); % Column vector

% Check dimensions
n = length(x);
if size(mu,1) ~= n | size(mu,2) ~= 1 | size(sigma,1) ~= n | ...
      size(sigma,2) ~= n
  error('Parameter dimensions must agree');
end


a = -(n/2) * log10(2*pi) - .5 * log10(det(sigma));
b = (-.5 * (x-mu).' * inv(sigma) * (x-mu)) / log(10);
y = a + b;
