我编写了这个脚本来创建一个向右滑动的函数,并且始终将绘图的两个点指定为黑点:
\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=-250
x=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}