![如何在轴环境中绘制布朗运动?](https://linux22.com/image/476249/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%BD%B4%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%BB%98%E5%88%B6%E5%B8%83%E6%9C%97%E8%BF%90%E5%8A%A8%EF%BC%9F.png)
我想画一个从时间 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;
}
那么,我需要如何调整宏呢?标准布朗运动的路径实际上应该是这样的