My code is the following. But it seems that my integral does not converge. What i'm doing wrong? clear all; close all; clc;
mu=[0.5, 2]; sigma=[1.5 0; 0 1.5]; beta=mvnrnd(mu, sigma,100); g = mvnpdf(beta,mu,sigma); Z=reshape(beta,1,[]);
n_max=10000; grid_x=linspace(1, 100, n_max); n=100;
crit=1/(10^6);
h=ones(n,1);
th=h;
for i=1:n x=grid_x(i);
h(i)=g(i,:)*h(i,:);
end
diff = abs(th - h);
fprintf('Iteration %3d: %.6f\n',i,diff);
% check for convergence
if(diff < crit)
fprintf('Value function iteration has converged.\n');
break;
end
% update the old value of h values with the new ones
h = th;