如何使函数图像平滑(无峰值)?

如何使函数图像平滑(无峰值)?

我画了图,但出现了山峰。

\documentclass{article}

\usepackage{tikz} 

\usepackage{xcolor}

\usepackage{amssymb}    

\begin{document}

\begin{center}

\begin{tikzpicture}[domain=-4:7] [scale=0.8]

    \draw[ultra thick, ->] (-4,0) -- (7.5,0) node[right] {$\textbf{X}$};

    \draw[ultra thick,->] (0,-2) -- (0,4.2) node[above] {$\textbf{Y}$};

    \draw[ultra thick,color=blue]   plot (\x,{sin(2*\x r)})   node[right] {$y = sen~ 2x$};

        \node at (1.5,-0.3) {$\textcolor[rgb]{1,0,0}{\frac{\pi}{2}}$};

        \node at (2.8,-0.3) {$\textcolor[rgb]{1,0,0}{\pi}$};

        \node at (4.7,-0.3) {$\textcolor[rgb]{1,0,0}{\frac{3\pi}{2}}$};

        \node at (6.3,-0.3) {$\textcolor[rgb]{1,0,0}{2\pi}$};

            \node at (-1.5,-0.3) {$\textcolor[rgb]{1,0,0}{-\frac{\pi}{2}}$};

                \node at (-3.2,-0.3) {$\textcolor[rgb]{1,0,0}{-\pi}$};

                \node at (-0.2,1) {1};

                    \node at (-0.2,-1) {-1};

            \end{tikzpicture}

\end{center}

\end{document}

在此处输入图片描述

答案1

您可以samples使用

\draw[ultra thick,color=blue]   plot[samples=100] (\x,{sin(2*\x r)})   node[right] {$y = sen~ 2x$};

根据需要调整值 100。

\documentclass{article}

\usepackage{tikz}

\usepackage{xcolor}

\usepackage{amssymb}    

\begin{document}

\begin{center}

\begin{tikzpicture}[domain=-4:7] [scale=0.8]

    \draw[ultra thick, ->] (-4,0) -- (7.5,0) node[right] {$\textbf{X}$};

    \draw[ultra thick,->] (0,-2) -- (0,4.2) node[above] {$\textbf{Y}$};

    \draw[ultra thick,color=blue]   plot[samples=100] (\x,{sin(2*\x r)})   node[right] {$y = \sin2x$};

        \node at (1.5,-0.3) {$\textcolor[rgb]{1,0,0}{\frac{\pi}{2}}$};

        \node at (2.8,-0.3) {$\textcolor[rgb]{1,0,0}{\pi}$};

        \node at (4.7,-0.3) {$\textcolor[rgb]{1,0,0}{\frac{3\pi}{2}}$};

        \node at (6.3,-0.3) {$\textcolor[rgb]{1,0,0}{2\pi}$};

            \node at (-1.5,-0.3) {$\textcolor[rgb]{1,0,0}{-\frac{\pi}{2}}$};

                \node at (-3.2,-0.3) {$\textcolor[rgb]{1,0,0}{-\pi}$};

                \node at (-0.2,1) {1};

                    \node at (-0.2,-1) {-1};

            \end{tikzpicture}

\end{center}

\end{document}

在此处输入图片描述

但有了pgfplots,这项工作就容易了。

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
            axis lines=middle,clip=false,
            xmin=-4,xmax=8,ymin=-2,ymax=2,
            ytick={-1,1},
            xtick={-3.14,-1.57,01.57,3.14,4.71,6.28},
            xticklabels={$\pi$,$\frac{\pi}{2}$,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$},
            xticklabel style={red},
            xlabel=$x$,
            ylabel=$y$
            ]
      \addplot[domain=-4:7,blue,thick,samples=100] {sin(deg(2*x))} node[anchor=west]{$y=\sin2x$};
    \end{axis}
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容