MATLAB Answers

0

Plotting the mean and variance of 100 Brownian/Wiener paths

Asked by Mel Hernandez on 8 Feb 2018
Latest activity Commented on by 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

Sign in to comment.

1 Answer

Answer by John D'Errico
on 8 Feb 2018
 Accepted Answer

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

  1 Comment

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today