How to write code with iterations for this integral?

The integral is the following : h(x)=integral(from a to b) of g(x,y)h(y)dy. I'm not so advanced in matlab. I know how to estimate Riemann integral, but don't know how to write iterated loop for convergence of left-hand side and right-hand side of h(x). Thank you.

Respuestas (1)

Nathalie
Nathalie el 19 de Feb. de 2014
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;

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Feb. de 2014

Respondida:

el 19 de Feb. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by