MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

A question regarding mvnpdf

Asked by antonet on 2 Apr 2013

Dear all,

I have a 2 by 1 variable u_t that varies across time t=1,....,T. This variable follows the multivariate normal N(0, (1\lambda_t)*Sigma) where lambda_t is a scalar , varies across time and follows a gamma density. Sigma is a 2 by 2 matrix.

I want to find the

 j=1: T
mvnpdf(u_t(j,:),(1\lambda)Sigma)
end

where lambda=the vector of all lambda_t's

But the mvnpdf does not allow for that since this product (1\lambda)Sigma makes no sense. Is there a way of finding

 mvnpdf(u_t(j,:),(1\lambda)Sigma) for each j?

1 Comment

antonet on 2 Apr 2013

Is something unclear to my question?

Products

No products are associated with this question.

Answer by Tom Lane on 2 Apr 2013

I'm not sure if the separate Sigma/lambda values correspond to the separate rows of u_t. If they do, here's an example where supply an array of Sigma values by stacking them in a 3-D array, and I multiply each Sigma by the corresponding lambda, and compute the density at the corresponding row of x.

>> x = [1 1;1 2;2 1];
>> mu = [0 0];
>> Sigma = cat(3,eye(2),2*eye(2),eye(2));
>> lambda = [1 .5 .6];
>> for j=1:3; disp(mvnpdf(x(j,:),mu,lambda(j)*Sigma(:,:,j))); end
0.0585
0.0131
0.0041
>> mvnpdf(x,mu,bsxfun(@times,reshape(lambda,[1 1 3]),Sigma))
ans =
0.0585
0.0131
0.0041


antonet on 2 Apr 2013

Dear Tom,

Thank you very much. You are very close to what I am asking for. For each u_t we have a different lamdba_t but the Sigma is the same for each row of u_t

In that case, how would your algorithm change?

Thank you so much!

Tom Lane on 3 Apr 2013

I see only two alternatives. One is to loop, each time supplying a single Sigma and the entire u_t array. The other is to expand both the u_t array and the Sigma 3-D array so that there are enough copies of each Sigma for each row of u_t, and enough copies of u_t for each Sigma. I think you'd be better of looping with a single Sigma matrix each time.

antonet on 3 Apr 2013

HI Tom. Can you possibly provide a sample code?

thanks