clear all
close all
clc


eps=1;
n=1;
while(eps>10^(-6))
        %X(n) = randn;
        X(n) =normal_RV(1);
        mean_X(n) =mean(X');
        var_X(n)=mean((X'-mean_X(n)).^2);
        kurt_X(n)=mean((X'-mean_X(n)).^4)/(var_X(n)^2);

        if(n==1)
                eps=1;
        else
                eps=abs(var_X(n)-var_X(n-1));
        end
n=n+1;
end
n
figure(1)
plot(mean_X,'r','Linewidth',2)
title('Convergence of mean')
ylabel('mean x')
axis([1 n -1 4])

 
figure(2)
plot(var_X,'r','Linewidth',2)
title('Convergence of variance')
ylabel('var x');
axis([1 n -1 4])

figure(3)
plot(kurt_X, 'r','Linewidth',2)
title('Convergence of kurtosis')
ylabel('kutosis x');
axis([1 n -1 4])


figure(4)
subplot(1,1,1)
hold on


for i=1:n,
            subplot(1,1,1)
            plot(i,var(mean_X(1:i-1)'),'*');
end;
subplot(1,1,1)
ylabel('variance of the mean of x');
xlabel('n');
hold off


figure(5)
subplot(1,1,1)
hold on
for i=1:n,
            subplot(1,1,1)
            plot(i,var(var_X(1:i-1)'),'*');
end;
subplot(1,1,1)
ylabel('variance of variance of x');
xlabel('n');
hold off

figure(6)
subplot(1,1,1)
hold on
for i=1:n,  
            subplot(1,1,1)
            plot(i,var(kurt_X(2:i-1)'),'*');
end;
subplot(1,1,1)
ylabel('variance of Kurtosis of x');
xlabel('n');
hold off