# Brownian motion and rotated normal distribution

I found this interesting and (I believe) quite pedagogic representation of a brownian motion and its related normal distribution at a specific time forward.

Tikz Brownian motion explains how to draw a brownian motion and Rotated normal distribution explains how to draw the rotated normal.

I join MWE below. At my level, it'd far too manual to match the graph and the center of the distribution. Is there a way to link the distribution and the brownian motion so that it shows how the brownian grows in $\sqrt(T)$. As a result, the graph on $T=100$ shows a narrower distribution than on $T=400$ ?

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

%Brownian motion
\newcommand{\BM}[5]{
% points, advance, rand factor, options, end label
\draw[#4] (0,0)
\foreach \x in {1,...,#1}
{   -- ++(#2,rand*#3)
}
node[right] {#5};
}

\begin{tikzpicture}[
declare function=    {gauss(\x,\y,\z)=\offset+1/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}]

\pgfmathsetseed{17}
\draw[help lines] (0,-5) grid (15,5);
\BM{100}{0.02}{0.2}{red}{$BM_1$};
\draw (2,-5) -- (2,5) coordinate[pos=0.6](x2) coordinate[pos=0.5] (y2);
\draw[-latex] (2,0) -- (4,0) node[below left,rotate=-90]{};
\BM{600}{0.02}{0.2}{blue}{$BM_3$}

\end{tikzpicture}

\end{document}


Merci !

• Hi Marmot, I tried to sketch something. I want to show there is an effect on where the brownian can be at a future point $t$ depending on the distance from $s$ to this future point $(t-s)$. The distribution of probability is a Gaussian with a variance $\sqrt{(t-s)}$ – Julien-Elie Taieb Jan 2 at 20:25
• I updated the details on my initial question. The variance of the distribution is determined by the distance to the future point we try to simulate. The farer the point, the wider the distribution. – Julien-Elie Taieb Jan 2 at 20:51
• Its definitiely the right direction and even better with the animation feature. May I just add one thing ? the projection should be on a straight vertical line and not on the distribution itself. It shows the idea of the potential impact at that specific time and how it is distributed. – Julien-Elie Taieb Jan 2 at 21:39
• – Julien-Elie Taieb Jan 2 at 21:46
• @Julien-ElieTaieb This seems to be a little bit unscientific/undidactic. The probability distribution applies before the time has passed, but the shown Brownian motion applies after the time has passed. – Toscho Jan 2 at 21:57

An attempt to clean up. It shows what (I think) we agreed on in this chat. The answer comes in two variations:

1. A more boring version which has a Gaussian that just moves to the right and gets wider.
2. A more funky version in which the Gaussian follows a path. (There are no claims attached that this version has a clear physical interpretation, but it leads to a more interesting animation. ;-)

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}

%Brownian motion
\newcommand{\BM}[5]{
% points, advance, rand factor, options, end label
\draw[#4] (0,0)
\foreach \x in {1,...,#1}
{   -- ++(#2,rand*#3) coordinate (aux-\x) % <- added coordinate names
}
node[right] {#5};
}
\draw[#1] let \p1=(aux-#2),\p2=(aux-#3),\n1={0.5*sqrt((\x2-\x1)*1pt/1cm)},
\n2={3*\n1},\n3={0.895*\n2} in \pgfextra{\pgfmathsetmacro{\ymax}{\n2}
\pgfmathsetmacro{\ynext}{\n3}}
plot[variable=\z,domain=-\ymax:\ymax,samples=101]
({\x2+3*gauss(\z,\n1,0)*1cm},{\y1+\z*1cm})
($(\x2,\y1)+(0,-\ymax)$) -- ($(\x2,\y1)+(0,\ymax)$)
foreach \X in {-\ymax,-\ynext,...,\ymax}
{ (\p1) -- ($(\x2,\y1)+({0*gauss(\X,\n1,0)},\X*1cm)$)};
}

\begin{tikzpicture}[
declare function={gauss(\x,\y,\z)=1/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}]

\pgfmathsetseed{17}
\draw[help lines] (0,-8) grid (15,8);
\BM{100}{0.02}{0.2}{red}{$BM_1$};

\draw (2,-5) -- (2,5) coordinate[pos=0.6](x2) coordinate[pos=0.5] (y2);
\draw[-latex] (2,0) -- (4,0) node[below left,rotate=-90]{};
\BM{600}{0.02}{0.2}{blue}{$BM_3$}

\end{tikzpicture}
\end{document}


This can be made an animation.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}

%Brownian motion
\newcommand{\BM}[5]{
% points, advance, rand factor, options, end label
\draw[#4] (0,0)
\foreach \x in {1,...,#1}
{   -- ++(#2,rand*#3) coordinate (aux-\x) % <- added coordinate names
}
node[right] {#5};
}
\draw[#1] let \p1=(aux-#2),\p2=(aux-#3),\n1={0.5*sqrt((\x2-\x1)*1pt/1cm)},
\n2={3*\n1},\n3={0.895*\n2} in \pgfextra{\pgfmathsetmacro{\ymax}{\n2}
\pgfmathsetmacro{\ynext}{\n3}}
plot[variable=\z,domain=-\ymax:\ymax,samples=101]
({\x2+3*gauss(\z,\n1,0)*1cm},{\y1+\z*1cm})
($(\x2,\y1)+(0,-\ymax)$) -- ($(\x2,\y1)+(0,\ymax)$)
foreach \X in {-\ymax,-\ynext,...,\ymax}
{ (\p1) -- ($(\x2,\y1)+({0*gauss(\X,\n1,0)},\X*1cm)$)};
}

\foreach \Z in {120,130,...,540}
{\begin{tikzpicture}[
declare function={gauss(\x,\y,\z)=1/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}]

\pgfmathsetseed{17}
\draw[help lines] (0,-8) grid (15,8);
\BM{100}{0.02}{0.2}{red}{$BM_1$};

\draw (2,-5) -- (2,5) coordinate[pos=0.6](x2) coordinate[pos=0.5] (y2);
\draw[-latex] (2,0) -- (4,0) node[below left,rotate=-90]{};
\BM{600}{0.02}{0.2}{blue}{$BM_3$}

\end{tikzpicture}}
\end{document}


Note that I have not computed the prefactor of the variance. This is just a cartoon. But this code will allow those who have a real random walk problem and compute the prefactor to produce a more realistic animation.

Now comes the comoving Gaussian. (To keep the answer reasonably "short" I only show the animation.)

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}

%Brownian motion
\newcommand{\BM}[5]{
% points, advance, rand factor, options, end label
\draw[#4] (0,0)
\foreach \x in {1,...,#1}
{   -- ++(#2,rand*#3) coordinate (aux-\x) % <- added coordinate names
}
node[right] {#5};
}
\draw[#1] let \p1=(aux-#2),\p2=(aux-#3),\n1={0.5*sqrt((\x2-\x1)*1pt/1cm)},
\n2={3*\n1},\n3={0.89*\n2} in \pgfextra{\pgfmathsetmacro{\ymax}{\n2}
\pgfmathsetmacro{\ynext}{\n3}}
plot[variable=\z,domain=-\ymax:\ymax,samples=101]
({\x2+3*gauss(\z,\n1,0)*1cm},{\y2+\z*1cm})
($(\p2)+(0,-\ymax)$) -- ($(\p2)+(0,\ymax)$)
foreach \X in {-\ymax,-\ynext,...,\ymax}
{ (\p1) -- ($(\p2)+({0*gauss(\X,\n1,0)},\X*1cm)$)};
}

\foreach \Z in {120,130,...,540}
{\begin{tikzpicture}[
declare function={gauss(\x,\y,\z)=1/(\y*sqrt(2*pi))*exp(-((\x-\z)^2)/(2*\y^2));}]

\pgfmathsetseed{17}
\draw[help lines] (0,-8) grid (15,8);
\BM{100}{0.02}{0.2}{red}{$BM_1$};

\draw (2,-5) -- (2,5) coordinate[pos=0.6](x2) coordinate[pos=0.5] (y2);
\draw[-latex] (2,0) -- (4,0) node[below left,rotate=-90]{};
\BM{600}{0.02}{0.2}{blue}{$BM_3$}