Plotting the mean and variance of 100 Brownian/Wiener paths
6 views (last 30 days)
Show older comments
Mel Hernandez
on 8 Feb 2018
Commented: Mel Hernandez
on 11 Feb 2018
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
0 Comments
Accepted Answer
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)
See Also
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!