clear all
clc

alpha=3;
beta=0.8;

x = -log(rand);

for i=1:10000;
    y = -1*beta*log(rand);
    u1 = rand;
    fun1 = fun4_prob1(x,y,alpha,beta);
    if u1 <=fun1
        x=y;
    else
        x=x;
    end;
    x_1(i)=x;
    exp_x(i) = mean(x_1);
    var_x(i) = var(x_1);
end;
figure(1)
hist(x_1);
     xlabel('x - Values')
     ylabel('f(x)')
     title(['Histogram of values from Markov Chain']);
     saveas(figure(1),['Histogram MC-Values prob1.png'])

exp_x1 = mean(x_1)
var_x1 = var(x_1)

figure(2)
func=@(x) x*x*abs(sin(pi*x))*exp(-abs(x)^3);
fplot(func,[0,3]);
     title(['Density Function f(x)']);
     saveas(figure(2),['Density Function prob1.png'])

figure(3)
plot(exp_x)
     xlabel('time')
     ylabel('E(x)')
     title(['Expected Value Convergence']);
saveas(figure(3),['Expected Convergence prob1.png'])

figure(4)
plot(var_x)
     xlabel('time')
     ylabel('Var(x)')
     title(['Variance Convergence']);
   
saveas(figure(4),['Variance Convergence prob1.png'])

