2
votes

I'm trying to calculate a bivariate normal distribution in matlab(with mvnpdf), but the pdf I obtain has a strange shape with several peaks.

http://i.stack.imgur.com/gmiFZ.png

This is the code I use:

s=[3,1]';
C_ee = [0.0473   -0.1446;
       -0.1446    0.4440]

x1 = -5:.2:5; x2 = -5:.2:5;
[X1,X2] = meshgrid(x1,x2);
F = mvnpdf([X1(:) X2(:)],s',C_ee);
F = reshape(F,length(x2),length(x1));
figure(1);
surf(x1,x2,F);
caxis([min(F(:))-.5*range(F(:)),max(F(:))]);
axis([-5 5 -5 5 0 5])
xlabel('Re'); ylabel('Im'); zlabel('Probability Density');

I've noticed, that when I increase the value of C_ee (sigma matrix), for instance C_ee+0.05 the shape starts to look normal.

I notice that this matrix is close to not being positive definite... but it still is.

Could anyone explain this behaviour?

Thank you for your time.

1

1 Answers

1
votes

The problem is too coarse sampling in the x1 and x2 axes. Try changing your sampling step .2 into .002 for example. Also, the pdf is concentrated on a small area, specially in the x1 direction. So you could "zoom" a little changing the interval endpoints. For example, use

x1 = 2:.002:4; x2 = -3:.002:4;

In the figures below I'm using

imagesc(x1, x2, F)

instead of surf(x1,x2,F) to get a better representation. First figure is with your original sampling, and second with x1 and x2 as in my line above. Comparing both figures, the sampling issue is evident. Note that the axis scales are different.

Original

Modified