% Simulation of a function of a Wiener process over many paths

T=1;
N=500;
dt=T/N;
t=dt:dt:1;
M=1000;
dW=sqrt(dt)*randn(M,N);
W=cumsum(dW,2);

U=exp(repmat(t,[M,1])+0.5*W);
% plot of few realizations of the function U
plot([0 t],[ones(5,1) U(1:5,:)])

% Estimation of the expectation of U
hold on
Umean=mean(U);
plot([0,t],[1,Umean],'r--')
% overlapping the plot of the exact expectation
plot([0,t],[1,exp(9*t/8)])