答案1
您只需要一个local bounding box
。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0, xmax = 30,
ymin = -1.5, ymax = 2.0,
]
\begin{scope}[local bounding box=plot]
\addplot[
domain = 0:30,
samples = 200,
smooth,
thick,
black,
] {exp(-x/10)*( cos(deg(x)) + sin(deg(x))/40 )};
\end{scope}
\end{axis}
\draw[dashed] (plot.north east) -- (plot.north west) node[left=2ex] {max}
(plot.south east) -- (plot.south west) node[left=2ex] {min};
\end{tikzpicture}
\end{document}
答案2
您必须找到函数的最小值。为此,我使用了 MATLAB 并找到最小 y 值为 -0.8106。
\documentclass[margin=3mm]{standalone}
%
\usepackage{tikz} % TikZ and PGF
\usepackage{pgfplots}
\usepackage{calc}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\def\a{1}
\begin{axis}[
xmin = 0, xmax = 30,
ymin = -1.5, ymax = 2.0,
]
\addplot[
domain = 0:30,
samples = 100,
smooth,
thick,
black,
] {\a*exp(-x/15)*( cos(deg(x)) + sin(deg(x))/40 )};
\addplot [domain = 0:30,
thick,
dashed,
blue,
]{\a};
\addplot [domain = 0:30,
thick,
dashed,
blue,
]{-0.8106};
\end{axis}
\end{tikzpicture}
\end{document}
答案3
您只需使用 \draw [dashed] (x1,y1) -- (x2,y2) 并插入所需的坐标即可实现直线。
我建议你看一下 Tikz 手册:http://ftp.fau.de/ctan/graphics/pgf/base/doc/pgfmanual.pdf