Plotting the Gaussian probability distribution for a Brownian process over time
9 views (last 30 days)
Show older comments
I am trying to plot the change in a Gaussian probability distribution over time, where the variance is 2Dt (as is the case for Brownian motion). I wish to plot the Gaussian probability disitrbution over the positions x, with a seperate plot for different observation times. This is my code:
time = [0.5, 1.0, 3.0, 5.0, 10.0];
figure();
for i = time
x = -20:0.01:20;
y = exp(-((x).^2)./2*i)*(1./sqrt(2*pi*i));
plot(x,y,'DisplayName',num2str(i));
hold on
end
legend
This is the final plot:

However, this is not how I expect this process to look. The curve should actually start as a relatively sharp peak and then flatten out over time, modelling the process of a freely diffusing particle. I am not sure what I am doing wrong here, as plotting the same expression in Desmos and parametrising time gives me the result I am looking for. An example for the kind of curves I should get:

I also tried plotting it using fplot, and defining x as a symbol. I got the same results.
Any help would be appreciated.
0 Comments
Accepted Answer
Dyuman Joshi
on 15 Dec 2023
The term inside exp() was not correct, as the 2*i term should be fully in the denominator, for which it needed to be enclosed in parenthesis. After the correction, the plots are as expected.
Additionally, as x is constant i.e. not varying with the loop, bring out of the loop.
I also noted that the formula in wikipedia uses 4 instead of 2 used in the formula below.
time = [0.5, 1.0, 3.0, 5.0, 10.0];
figure();
hold on
x = -20:0.01:20;
for i = time
% v v
y = exp(-((x).^2)./(2*i))*(1./sqrt(2*pi*i));
plot(x,y,'DisplayName',num2str(i));
end
legend
More Answers (0)
See Also
Categories
Find more on Annotations 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!