無法將函數點新增至繪圖中 (gif)

無法將函數點新增至繪圖中 (gif)

我編寫此腳本是為了創建一個向右滑動的函數,並且始終將繪圖的兩個點指定為黑點:

\documentclass[tikz]{standalone}
 \usepackage{tikz,pgfplots}
 \pgfplotsset{compat=1.16}
 \pgfplotsset{ticks=none}
 \begin{document}
 \tikzset{declare function={bellshape(\x,\mu,\sigma)=exp(-(\x-\mu)^2/(2*\sigma^2));}}
 \usetikzlibrary{intersections}
 \foreach \center in {-5,-4.9,...,5}
 {
   \begin{tikzpicture}
       \begin{axis}[scale=3,
                   width=4cm,
                   xmin=-3, xmax=3, 
                   ymin=-.05, ymax=1.4,
                   axis line style={draw=none},
                   ]
           \addplot [only marks, samples at={-3,3}]
             {bellshape(x,\center,.5)};
           \addplot [domain=-5:5, samples=300,color=blue, name path=A]
             {bellshape(x,\center,.5)};
       \end{axis}
   \end{tikzpicture}
 }
 \end{document}

這正是我的意圖:

在此輸入影像描述 但我也在嘗試為下面的波包製作一個。

\documentclass[tikz]{standalone}
  \usepackage{tikz,pgfplots}
  \pgfplotsset{compat=1.16}
  \pgfplotsset{ticks=none}
  \begin{document}
  \tikzset{declare function={bellshape(\x,\mu,\sigma)=exp(-(\x-\mu)^2/(2*\sigma^2));}}
  \usetikzlibrary{intersections}
  \foreach \center in {-350,-320,...,350}
  {
    \begin{tikzpicture}
        \begin{axis}[scale=3,
                    width=4cm,
                    xmin=-250, xmax=250, 
                    ymin=-1, ymax=1,
                    axis line style={draw=none},
                    ]
            \addplot [only marks, samples at={-250,250}]
            {.1*(bellshape(x,\center-100,25)+bellshape(x,\center-50,25)+bellshape(x,\     center,25)+bellshape(x,\center+50,25)+bellshape(x,\center+100,25))*sin(     deg(20*pi*x))};
            \addplot [domain=-600:600,samples=400,color=blue]
            {.1*(bellshape(x,\center-100,25)+bellshape(x,\center-50,25)+bellshape(x,\     center,25)+bellshape(x,\center+50,25)+bellshape(x,\center+100,25))*sin(     deg(20*pi*x))};
        \end{axis}
    \end{tikzpicture}
  }
  \end{document}

我遵循相同的想法(將藍線的相同函數放入僅兩個黑點的函數中),但我沒有從兩個黑點得到任何運動。當我嘗試取出“sin”函數時,黑點會移動到“bellshape”函數,所以我相信錯誤一定與sin函數有關?有人知道什麼可以解決這個問題?

在此輸入影像描述

答案1

您的程式碼中有一些我不明白的事情,最重要的是波包的參數化。在你的情況下,它是高斯的總和,每個高斯以相同的速度移動,乘以總體固定式階段。為什麼?無論如何,這就是為什麼你會得到你所觀察到的效果。該samples at圖乘以,在和*sin(deg(20*pi*x))處為零。x=-250x=250

我會選擇一個可以說是更物理化的波包。

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\pgfplotsset{ticks=none}
\begin{document}
\tikzset{declare function={bellshape(\x,\mu,\sigma)=exp(-(\x-\mu)^2/(2*\sigma^2));
wavepacket(\x,\mu,\sigma,\k)=bellshape(\x,\mu,\sigma)*sin(\k*(\x-\mu));}}
\foreach \X in {-350,-320,...,350}
  {
    \begin{tikzpicture}
        \begin{axis}[%scale=3,
                    width=4cm,
                    xmin=-250, xmax=250, 
                    ymin=-1, ymax=1,
                    axis line style={draw=none},
                    ]
  \addplot [only marks, samples at={-250,250}]
            {0.1*(wavepacket(x,\X-100,25,4)+
                wavepacket(x,\X-50,25,4)+
                wavepacket(x,\X-25,25,4)+
                wavepacket(x,\X+25,25,4)+
                wavepacket(x,\X+50,25,4)+
                wavepacket(x,\X+100,25,4))};
  \addplot [domain=-250:250,samples=251,color=blue,smooth]
            {0.1*(wavepacket(x,\X-100,25,4)+
                wavepacket(x,\X-50,25,4)+
                wavepacket(x,\X-25,25,4)+
                wavepacket(x,\X+25,25,4)+
                wavepacket(x,\X+50,25,4)+
                wavepacket(x,\X+100,25,4))};
        \end{axis}
    \end{tikzpicture}
  }
\end{document}

在此輸入影像描述

相關內容