Graphics, Figures & Tables ⇒ Branching Brownian Motion
Branching Brownian Motion
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- Stefan Kottwitz
- Site Admin
- Posts: 10348
- Joined: Mon Mar 10, 2008 9:44 pm
Branching Brownian Motion
Yes, it would be easily possible with TikZ, or PSTricks, or calculations done with Lua. I would use pgfplots, since it gives us a coordinate system with axes and many options for customizing.
Jake gave an example here:
Code: Select all
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
% Create a function for generating inverse normally distributed numbers using the Box–Muller transform
\pgfmathdeclarefunction{invgauss}{2}{%
\pgfmathparse{sqrt(-2*ln(#1))*cos(deg(2*pi*#2))}%
}
% Code for brownian motion
\makeatletter
\pgfplotsset{
table/.cd,
brownian motion/.style={
create on use/brown/.style={
create col/expr accum={
(\coordindex>0)*(
max(
min(
invgauss(rnd,rnd)*0.1+\pgfmathaccuma,
\pgfplots@brownian@max
),
\pgfplots@brownian@min
)
) + (\coordindex<1)*\pgfplots@brownian@start
}{\pgfplots@brownian@start}
},
y=brown, x expr={\coordindex},
brownian motion/.cd,
#1,
/.cd
},
brownian motion/.cd,
min/.store in=\pgfplots@brownian@min,
min=-inf,
max/.store in=\pgfplots@brownian@max,
max=inf,
start/.store in=\pgfplots@brownian@start,
start=0
}
\makeatother
%
% Initialise an empty table with a certain number of rows
\pgfplotstablenew{201}\loadedtable % How many steps?
\begin{document}
\pgfplotsset{
no markers,
xmin=0,
enlarge x limits=false,
scaled y ticks=false,
ymin=-1, ymax=1
}
\tikzset{line join=bevel}
\pgfmathsetseed{3}
\begin{tikzpicture}
\begin{axis}
\addplot table [brownian motion] {\loadedtable};
\addplot table [brownian motion] {\loadedtable};
\end{axis}
\end{tikzpicture}
\pgfmathsetseed{3}
\begin{tikzpicture}
\begin{axis}
\addplot table [
brownian motion={%
max=0.5,
min=-0.75
}
] {\loadedtable};
\addplot table [
brownian motion={%
start=0.5,
min=-0.5, max=0.75
}
] {\loadedtable};
\end{axis}
\end{tikzpicture}
\end{document}
StefanThis approach uses pgfplotstable to calculate the Brownian motions as cumulative sums of random normally distributed values (thanks to horchler for pointing out the need for normality). You have to first initialise an empty table, using something like\pgfplotstablenew{200}\loadedtable
, and then you can draw the brownian motions using\addplot table [brownian motion] {\loadedtable};
.
You can set the initial value and the maximum and minimum values using
Code: Select all
\addplot table [brownian motion={start=0.5, min=-1, max=1}] {\loadedtable};