如何在軸環境內繪製布朗運動?

如何在軸環境內繪製布朗運動?

我想畫一個從時間 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;
}

那麼,我需要如何調整巨集呢?標準布朗運動的路徑其實應該是這樣的

在此輸入影像描述

相關內容