![如何在軸環境內繪製布朗運動?](https://rvso.com/image/476249/%E5%A6%82%E4%BD%95%E5%9C%A8%E8%BB%B8%E7%92%B0%E5%A2%83%E5%85%A7%E7%B9%AA%E8%A3%BD%E5%B8%83%E6%9C%97%E9%81%8B%E5%8B%95%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;
}
那麼,我需要如何調整巨集呢?標準布朗運動的路徑其實應該是這樣的