I tried to write a code in matlab. The code is supposed to be an easy task. I just want to compute the gaussian density for a single value. This is the code:

iteration = 1;

for iter = 1:iteration

i = 1;

while(i 0.5

j = 1;

prob = 0;

disp("more than half");

prob = computeProb(X((i),1),theta.tau(j),theta.mu(j),sqrt(theta.Sigma(j)));

fprintf('prob: %f \n', prob);

else

j = 2;

prob = 0;

disp("less than half");

prob = computeProb((X((i),1),theta.tau(j),theta.mu(j),sqrt(theta.Sigma(j)));

fprintf('prob: %f \n', prob);

end

i = i+1;

end

end

And this is the function to compute the density:

function q = computeProb( x,pi,mu,sd )

q= 1/(sd*sqrt(2*pi)) .* exp(-((x-mu)^2 / (2*(sd)^2)));

End

The Problem is ,the result of prob does not work if the u1

More Aisyah mat jasin's questions See All
Similar questions and discussions