I have a question regarding the visualization of Brownian Motion. I am using Jake's code from this topic: How to draw Brownian motions in tikz/pgf.
\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}
[xlabel= {\scriptsize $t$},ylabel = {\scriptsize BM},xticklabels={,,},yticklabels={,,},]
\addplot table [brownian motion] {\loadedtable};
\addplot table [brownian motion={start=0.5,min=-0.5, max=0.75}] {\loadedtable};
\end{axis}
\end{tikzpicture}
\end{document}
This gives me a red and a blue Brownian motion graph. My question should actually be quite simple, but I did not find an answer that worked for me. How can I perform mathematical operations on these two graphs (e.g.: plot a new graph that is the sum of the blue and red BM, or plot the square the red BM)?