挤压定理的 Tikz 插图?

挤压定理的 Tikz 插图?

我想知道是否可以使用 tikz 重新创建下图 在此处输入图片描述 这是挤压定理的一个例子。更简单的版本是绘制以下 在此处输入图片描述 但即使有了这个,我也没法得到确切的情节。这是我的 MWE

\documentclass[border=3mm,tikz]{standalone}
\usepackage{pgfplots} 
\begin{document} 
\begin{tikzpicture}
\begin{axis}[
    width=6cm,
 axis lines=middle,
 ticklabel style={fill=white},
 xmin=-1.5,xmax=1.5,
 ymin=-1.2,ymax=1.5,,
 xlabel=$x$,ylabel=$y$,
        ]
\addplot[blue,samples=50,domain=-1.5:-0.2,smooth] {x*x*sin(1/\x r)};
\addplot[blue,samples=1000,domain=-0.2:-0.02]   {x*x*sin(1/\x r)};
\addplot[blue,samples=1000,domain=0.02: 0.20]   {x*x*sin(1/\x r)};
\addplot[blue,samples=50,domain= 0.2: 1.5,smooth] {x*x*sin(1/\x r)};
\addplot[red,samples=50,domain=-1.5:1.5,smooth] {x*x};
\addplot[red,samples=50,domain=-1.5:1.5,smooth] {-x*x};
\end{axis}
\end{tikzpicture}
\end{document} 

已编辑:似乎每个人都忘记给出第一个图表的解决方案。这是 MWE

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} 
\draw[->] (-0.5,0) -- (6,0) node[below] {$x$};
    \draw[->] (0,-0.5) -- (0,5) node[left] {$y$}; 
      \draw[red,ultra thick] (-.5,1) to[out=-45,in=185,looseness=2] (4,2) to[out=0,in=135,looseness=1] node [at end,below] {$f$} (6,.5);
      \draw[blue,ultra thick] (-.5,2.5) to[out=25,in=160,looseness=1] (4,2) to[out=10,in=180,looseness=1] node [at end,above] {$h$} (6,3);
      \draw[green,ultra thick] (0.5,3.2) to[out=-45,in=175,looseness=1] (4,2) to[out=0,in=180,looseness=1] node [at end,below] {$g$} (6,2.5);
      \draw[dashed] (4,0) -- node[at start,below] {$a$} (4,2) -- node[at end,left] {$L$} (0,2);
    \end{tikzpicture}
\end{document}

任何修改(重新创建第一个图表)都值得赞赏!

答案1

像这样?

在此处输入图片描述

您需要增加正弦曲线的频率......

\documentclass[border=3mm,tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width=6cm,
 axis lines=middle,
 ticklabel style={fill=white},
 xmin=-1.5,xmax=1.5,
 ymin=-1.75,ymax=1.75,
 xlabel=$x$,ylabel=$y$,
 domain=-1.5:1.5,
 samples=200,
 smooth
        ]
\addplot[blue] {x*x*sin(4/\x r)};
\addplot[red] { x*x};
\addplot[red] {-x*x};
\end{axis}
\end{tikzpicture}
\end{document}

答案2

这是答案 在此处输入图片描述

\documentclass[usenames,dvipsnames]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\begin{document}
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (6,0) node[below] {$x$};
\draw[->] (0,-0.5) -- (0,5) node[left] {$y$};
\draw[red,thick] (-.5,1) to[out=-45,in=185,looseness=2] (4,2) to[out=0,in=135,looseness=1] node [at end,below] {$f$} (6,.6);
\draw[blue,thick] (-.5,2.5) to[out=25,in=160,looseness=1] (4,2) to[out=10,in=180,looseness=1] node [at end,above] {$h$} (6,3);
\draw[OliveGreen,thick] (0.5,3.2) to[out=-45,in=175,looseness=1] (4,2) to[out=0,in=180,looseness=1] node [at end,below] {$g$} (6,2.5);
\draw[dashed] (4,0) -- node[at start,below] {$a$} (4,2) -- node[at end,left] {$L$} (0,2);
\end{tikzpicture}
\end{document} 

答案3

尝试使用 MetaPost,两个轴共享相同的刻度,但使用函数 sin(pi/x) 而不是 sin(1/x)。它至少可以为设置提供一些想法。使用 LuaLaTeX 排版。

\documentclass{article}
\usepackage{luamplib}
    \mplibsetformat{metafun}
    \mplibnumbersystem{double}
\begin{document}
\begin{mplibcode}
     vardef function(expr xmin, xmax, xstep)(text f_x) =
        save x; x := xmin;
        (x, f_x) forever: hide(x := x + xstep) exitif x > xmax; .. (x, f_x) endfor
        if x - xstep < xmax: hide(x := xmax) .. (x, f_x) fi
    enddef;
    beginfig(1);
        u = v = 6cm;
        xmax = -xmin = .75; ymax = -ymin = .6; xstep = .01;
        vardef f(expr x) = x**2 enddef;
        vardef g(expr x) = f(x)*sin(pi/x) enddef;

        drawarrow (xmin*u, 0) -- (xmax*u, 0);
        label.bot(btex $x$ etex, (xmax*u, 0));
        drawarrow (0, ymin*v) -- (0, ymax*v);
        label.lft(btex $y$ etex, (0, ymax*v));

        path parabola[]; 
        parabola1 = function(xmin, xmax, xstep)(f(x)) xyscaled (u, v);
        parabola[2] = parabola1 reflectedabout (origin, (1, 0)); 
        for i = 1, 2: draw parabola[i]; endfor;
        label.top(btex $y=x^2$ etex, point infinity of parabola1);
        label.bot(btex $y=-x^2$ etex, point infinity of parabola2);
        draw function(xmin, xmax, 1E-4)(g(x)) xyscaled (u, v) withcolor blue;
    endfig;
\end{mplibcode}
\end{document}

在此处输入图片描述

答案4

啊,三年后……看来你喜欢重现你的第一幅图像,而不是第二幅(在问题中,这有点误导)。它可以简单地完成“pgfplots:

\documentclass[margin=3.14159mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[
lbl/.style = {fill=white, inner sep=1pt, font=\footnotesize}
                        ]
\begin{axis}[axis lines=middle,%center,
             axis line style= {-Straight Barb},
             xmin=-0.5, xmax=7,
             ymin=-0.5, ymax=6,
             xlabel=$x$, ylabel=$y$,
             label style = {below left},
             xtick=\empty, ytick=\empty,
             every axis plot post/.append style={very thick},
             no marks, smooth]
\addplot coordinates {(-0.5,2.5) (1.5,3) (4.2,2) (5.5,4) (6,4)} 
        node[above] {$h$};
\addplot coordinates {(-0.5,1) (1.5,0.1) (4.2,2) (6,1)}
        node[below] {$g$};
\addplot coordinates {(0.5,3.2) (4.2,2) (6,3)}
        node[below] {$f$};
\draw[dashed] (0,2) node[left] {$L$} -| (4.2,0) node[below] {$a$};
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容