绘制正弦波

绘制正弦波

我需要使用 LaTeX 绘制这两个图表,但到目前为止还没有成功。

在此处输入图片描述

在此处输入图片描述

这是我最接近第一个的(对于第二个,不幸的是我没有 MWE)

 \documentclass[14pt]{extarticle}

  \usepackage[margin=1in]{geometry} 
  \usepackage{etoolbox}
  \usepackage{tikz}
  \usetikzlibrary{calc,patterns,angles,quotes}
  \usetikzlibrary{through,arrows,shapes,trees,positioning}
  \usepackage{pgfplots}
  \usepackage{accents}
  \pgfplotsset{width=7cm,compat=newest}
  \usepackage{accents}
  \usepackage{calc}
  \usepackage{pst-node}
  \makeatletter
\pgfplotsset{
/tikz/max node/.style={
    anchor=south
},
/tikz/min node/.style={
    anchor=north
},
mark min/.style={
    point meta rel=per plot,
    visualization depends on={x \as \xvalue},
    scatter/@pre marker code/.code={%
        \ifx\pgfplotspointmeta\pgfplots@metamin
            \def\markopts{}%
            \node [min node] {
                \pgfmathprintnumber[fixed]{\xvalue},%
                \pgfmathprintnumber[fixed]{\pgfplotspointmeta}
            };
        \else
            \def\markopts{mark=none}
        \fi
        \expandafter\scope\expandafter[\markopts,every node near coord/.style=green]
    },%
    scatter/@post marker code/.code={%
        \endscope
    },
    scatter,
},
mark max/.style={
    point meta rel=per plot,
    visualization depends on={x \as \xvalue},
    scatter/@pre marker code/.code={%
    \ifx\pgfplotspointmeta\pgfplots@metamax
        \def\markopts{}%
        \node [max node] {
            \pgfmathprintnumber[fixed]{\xvalue},%
            \pgfmathprintnumber[fixed]{\pgfplotspointmeta}
        };
    \else
        \def\markopts{mark=none}
    \fi
        \expandafter\scope\expandafter[\markopts]
    },%
    scatter/@post marker code/.code={%
        \endscope
    },
    scatter
}
}
\makeatother


  \begin{document}
  \begin{tikzpicture}
  \begin{axis}[
  xlabel=$$,
  ylabel=$$
  ]
  \addplot[mark min, every node near coord/.style=] {sin(deg(x))};
  \end{axis}
  \end{tikzpicture}

  \end{document}

先感谢您

答案1

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\tikzset{declare function={f(\x)=2+1.2*sin(deg(\x))+0.3*\x;}}
\begin{tikzpicture}
 \draw[-latex](0,0) -- (8,0) node[below]{$x$};
 \draw[-latex](0,0) -- (0,5) node[left]{$y$};
 \draw plot[domain=0:6,variable=\x,samples=100] ({\x+1},{f(\x)});
 \foreach \X in {1,...,6}
 {\draw[dashed] ({\X},0) -- ({\X},{f(\X-1)+0.2});
 \node[circle,draw,fill,label=above:$f_\X$,scale=0.3] at ({\X+0.5},{f(\X-0.5)}){}; 
 }
 \draw[dashed] (7,0) -- (7,{f(6)+0.2});
 \draw(1,0.2) -- (1,-0.2) node[below]{$a$};
 \draw(7,0.2) -- (7,-0.2) node[below]{$b$};
\end{tikzpicture}
\tikzset{declare function={g(\x)=0.6+0.4*sin(deg(\x))+0.15*\x;}}
\begin{tikzpicture}
 \draw[-latex](0,0) -- (8,0) node[below]{$x$};
 \draw[-latex](0,0) -- (0,5) node[left]{$y$};
 \draw plot[domain=0:6,variable=\x,samples=100] ({\x+1},{f(\x)});
 \draw plot[domain=0:6,variable=\x,samples=100] ({\x+1},{g(\x)});
 \foreach \X in {1,...,6}
 {\draw[dashed] ({\X},0) -- ({\X},{f(\X-1)+0.2});
 \node[circle,draw,fill,label=above:$f_\X$,scale=0.3] at ({\X+0.5},{f(\X-0.5)}){}; 
 \node[circle,draw,fill,label=below:$g_\X$,scale=0.3] at ({\X+0.5},{g(\X-0.5)}){}; 
 }
 \draw[dashed] (7,0) -- (7,{f(6)+0.2});
 \draw(1,0.2) -- (1,-0.2) node[below]{$a$};
 \draw(7,0.2) -- (7,-0.2) node[below]{$b$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容