我试图让这波硬币波随着时间的推移按照指数衰减曲线衰减,就像下图所示的那样。 我已经完成了这段代码,但我不知道如何将峰值拟合到曲线。这是我的代码:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
trig format plots = rad,
axis lines = middle,
enlargelimits,
xlabel={$t$},
ylabel={$x$},
xlabel style={right},
ylabel style={above},
xtick=\empty,
ytick={1,0.5,-0.5,-1},
yticklabels={$A$,,,$-A$},
]
\addplot[very thick,cyan,domain=0:8*pi,samples=200] {cos(x)};
\addplot[dashed,domain=0:8*pi,samples=200] {exp(-0.2*x)};
\addplot[dashed,domain=0:8*pi,samples=200] {-exp(-0.2*x)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
sin
这是一个使用和运算符的纯 TikZ 解决方案cos
(无需搜索好的samples
值)。
注意:这是真实函数的近似值!
\documentclass[tikz]{standalone}
\begin{document}
\def\cycles{16}
\pgfmathsetmacro\cyclesminusone{\cycles-1}
\begin{tikzpicture}[x={5cm/\cycles},y=2.5cm,line join=round]
\draw[-stealth] (-1,0) -- (\cycles+1,0) node[right]{$t$};
\draw[-stealth] (0,-1.1) -- (0,1.1) node[above]{$x$};
\draw (0,1) +(.2,0) -- +(-.2,0) node[left]{$A$};
\draw (0,-1) +(.2,0) -- +(-.2,0) node[left]{$-A$};
\draw[cyan,very thick] (0,1)
\foreach \tp in {0,1,...,\cyclesminusone}{
cos(\tp+.25,0)
sin(\tp+.5,{-exp(-.2*(\tp+.5))})
cos(\tp+.75,0)
sin(\tp+1,{exp(-.2*(\tp+1))})
};
\draw[dashed] plot[domain=0:\cycles] (\x,{exp(-.2*\x)});
\draw[dashed] plot[domain=0:\cycles] (\x,{-exp(-.2*\x)});
\end{tikzpicture}
\end{document}
答案2
您只需要对波形信号使用正确的函数:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
trig format plots = rad,
axis lines = middle,
enlargelimits,
xlabel={$t$},
ylabel={$x$},
xlabel style={right},
ylabel style={above},
xtick=\empty,
ytick={1,0.5,-0.5,-1},
yticklabels={$A$,,,$-A$},
]
\addplot[very thick,cyan] {(exp(-0.2*x))*cos(x)};% <-- correct function for wave signal
\addplot[dashed] { exp(-0.2*x)};
\addplot[dashed] {-exp(-0.2*x)};
\end{axis}
\end{tikzpicture}
\end{document}
编辑: 和
\addplot[very thick,cyan] {(exp(-0.2*x))*cos(3*x)};% <-- changed wave's base frequency
你将获得: