%X~exp RV mean 1	Z = 1-exp(-3/x^2)
clear all
close all
clc
eps=1;
n=1;

while(eps > 10^(-6))
	Z(n) = 1-exp(-3/(exponential_RV(rand))^2);
	mean_Z(n)=mean(Z');
	var_Z(n) = mean((Z'-mean_Z(n)).^2);
	
	if(n<10)
		eps=1;
	else
		eps=abs(var_Z(n)-var_Z(n-1));
	end;
n=n+1;
end;


figure(3)
subplot(2,1,1)
plot(mean_Z,'r','LineWidth',2)
title('convergence of expected value of Z as function of n')
ylabel('Expected value of Z');
axis([1 n -1 4])

n
subplot(2,1,2)
hold on

for i=1:n
	subplot(2,1,2)
	plot(i,var(mean_Z(1:i-1)'),'*');
end;

subplot(2,1,2)
ylabel('variance of Expected value of Z');
xlabel('n')
hold off


