clear all
close all

lambda = .1;
Nmax = 2000;

y = rand;

x = -1/lambda*log(1-y);
m(1) = x;
s(1) = 1/lambda;
for i = 2:Nmax
y = rand;

x = -1/lambda*log(1-y);
s(i) = sqrt(1/i*(1/lambda^2));

m(i) = 1/i*((i-1)*m(i-1)+x);
end;
figure 
Mline = plot(m)
title('media campionaria con intervalli di confidenza')
hold on
%plot(1/lambda+2*s,':r');

%plot(1/lambda-2*s,':r');

ConfLine = plot(m+2*s,':r');

ConfLine2 = plot(m-2*s,':r');

Truemean = plot(ones(size(m))/lambda,'g')


legend([Mline ConfLine Truemean],'Media Campionaria','Intervallo di Confidenza','Media Vera')

