## Plotting the mean and variance of 100 Brownian/Wiener paths

Asked by Mel Hernandez

### Mel Hernandez (view profile)

on 8 Feb 2018
Latest activity Commented on by Mel Hernandez

### Mel Hernandez (view profile)

on 11 Feb 2018
Accepted Answer by John D'Errico

### John D'Errico (view profile)

I'm trying to plot the mean of 100 Brownian paths. I have the Brownian script correct, but when I try plotting the mean and variance, it's giving me the whole 100 paths instead of just one for the mean. This is my code. Thank you.
figure; hold on; grid on;
for i = 1:100
W(:,i) = brownianPath(1,200);
l1 = mean(W,2);
l2 = var(W,2);
plot(l1,'g-');
end

### John D'Errico (view profile)

Answer by John D'Errico

### John D'Errico (view profile)

on 8 Feb 2018

Computing the mean INSIDE the loop is wrong.
If you will compute the paths in a loop, wait until after the loop to compute the mean and variance. So perhaps this might be closer to what you wanted to see:
figure; hold on; grid on;
for i = 1:100
W(:,i) = brownianPath(1,200);
end
l1 = mean(W,2);
l2 = var(W,2);
plot(l1,'g-');

Mel Hernandez

### Mel Hernandez (view profile)

on 11 Feb 2018
Thank you so much!