我想画一个从时间 0 到 1 的标准布朗运动。这个答案,我尝试了以下方法:
\documentclass{article}
\usepackage{pgfplots, tikz}
\pgfplotsset{compat = newest}
\newcommand{\Emmett}[5] % color, x0, dt, n
{
\draw[#1] (0, #2)
\foreach\x in {1, ..., #4} {
-- ++(#3, rand * #3)
}
node[right] {#5};
}
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{axis}[
axis x line = center,
axis y line = center,
xtick = {0, ..., 1},
ytick = {-1, ..., 1},
xlabel = {$t$},
ylabel = {$x$},
xlabel style = {right},
ylabel style = {above},
xmin = 0,
xmax = 1.1,
ymin = -1,
ymax = 1]
\Emmett{black}{0}{.01}{100}{};
\end{axis}
\end{tikzpicture}
\end{document}
输出为
因此显然存在错误。我必须承认,我并不完全理解这个\Emmett
宏,很可能它存在错误。代码实际上应该执行以下操作:
t = 0;
x = x0;
for (i = 0; i < n; ++i)
{
plot (t, x);
let xi be a sample from the standard normal distribution;
x += sqrt(dt) * xi;
}
那么,我需要如何调整宏呢?标准布朗运动的路径实际上应该是这样的