I'm trying to use the meshgrid "function" in Matlab to generate the value of the characteristic function phi of a bivariate normal distribution. Currently I am using two-for loops to do this.
for i = 1:M
for j = 1:M
U = [u1(i); u2(j)];
phi(i,j) = exp(-1i*mu*U-0.5*U'*SIGMA*U);
end
end
Here u1 and u2 are the two vectors spanning the space for which values phi can take. However, this double for-loop is very time consuming, and I would like to do this using a meshgrid approach.
U = meshgrid(u1,u2);
PHI = exp(-1i*mu*[U1(:) U2(:)]-0.5*[U1(:) U2(:)]'*SIGMA.*[U1(:) U2(:)]);
I am trying to do this using the code above. But this is definitely not working due to the different dimensions of mu and [U1(:) U2(:)]. Do anyone have any hints on how this can be done?