How to write code with iterations for this integral?

1 次查看(过去 30 天)
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.

回答(1 个)

Nathalie
Nathalie 2014-2-19
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;

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by