How to write code with iterations for this integral?

조회 수: 1 (최근 30일)
Nathalie
Nathalie 2014년 2월 19일
답변: Nathalie 2014년 2월 19일
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