Plotting the mean and variance of 100 Brownian/Wiener paths

6 views (last 30 days)
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

Accepted Answer

John D'Errico
John D'Errico 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-');

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!