Professional Documents
Culture Documents
∫ e x dx
0
->
e 2−1
2
2* ∫ e ∗0.5 dx =2 E ( e ) , x
( 0
x
) x
U (0,2)
% MCIntegration
clc;clear all
rand('seed',0);
N=1000;
meanexp=zeros(1,N);
for i=(1:N)
meanexp(i)=2*mean(exp(random('uniform',0,2,1,i)));
end
ans=exp(2)-1
exp10=meanexp(10)
exp100=meanexp(100)
exp1000=meanexp(1000)
plot(1:N,meanexp);
Output:
ans =
6.3891
exp10 =
5.9957
exp100 =
6.3768
exp1000 =
6.3803
3
0 100 200 300 400 500 600 700 800 900 1000