フィルターのクリア

why mvnpdf returns complex values?

3 ビュー (過去 30 日間)
Nicola Donelli
Nicola Donelli 2015 年 1 月 14 日
回答済み: Nicola Donelli 2015 年 1 月 14 日
Hi, can anybody tell me why sometimes (i.e. with some Variance Matrices) the mvnpdf returns complex values? As far as I know the multivariate normal density is a function from R^d to R...
Thanks

採用された回答

Torsten
Torsten 2015 年 1 月 14 日
% FUNCTION Y = 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 = 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 = (2*pi)^-(n/2) * det(sigma)^-.5;
b = exp(-.5 * (x-mu).' * inv(sigma) * (x-mu));
y = a * b;
Just check by your own which Expression (a or b) becomes complex in your application.
Best wishes
Torsten.
  1 件のコメント
Torsten
Torsten 2015 年 1 月 14 日
Are you sure the covariance matrices you supply are all positive definite ?
Otherwise, the factor "a" may become complex.
Best wishes
Torsten.

サインインしてコメントする。

その他の回答 (1 件)

Nicola Donelli
Nicola Donelli 2015 年 1 月 14 日
Thanks a lot. I simply unintentionally used a complex value as input.
Sorry for the silly question!

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by