%Exercise (2c), ex sheet 1

alpha = 0.6;
N = 10000;
M = 1000;
x = zeros(M,N);
y = zeros(M,N);
Delta_t = 1/N;
xi = randn(M,N); % iid gaussian rv's
xi2 = 2*(unidrnd(2,M,N)-1) - 1; %iid uniform rv's with P(xi2=1) = P(xi2=-1) = 1/2

for m=1:M
    for i = 1:(N-1)
        x(m,i+1) = x(m,i) + (Delta_t)^alpha*xi(m,i);
        y(m,i+1) = y(m,i) + (Delta_t)^alpha*xi2(m,i);
    end;
end;

%Plot a trajectory

figure;
plot(1:N,x(1,1:N));

%Plot histograms
nbins = 20;
figure;
hist(x(1:M,N),nbins);
xlabel('X_N')
%ylabel('')
title('gaussian RVs, alpha = 0.4')

figure;
hist(y(1:M,N),nbins);
h = findobj(gca,'Type','patch');
set(h,'FaceColor','r','EdgeColor','w')
xlabel('X_N')
%ylabel('')
title('uniform RVs, alpha = 0.4')

mean1 = mean(x(1:M,N));
var1 = std(x(1:M,N));
mean2 = mean(y(1:M,N));
var2 = std(y(1:M,N));
