%Exercise (2a), ex sheet 1

N = 100;
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) + sqrt(Delta_t)*xi(m,i);
        y(m,i+1) = y(m,i) + sqrt(Delta_t)*xi2(m,i);
    end;
end;

%Plot a trajectory

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

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

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')

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