8

I am very new to drawing graphs using tikz. I want to draw the graph of the following function $f(x)=x^a\sin(x^{-b})$ for $x>0$. The outcome should be exactly the same as the picture of page 118 of the book "Real Analysis" by Stein & Shakarchi.

enter image description here

Here I don't mean to violate the copyright of the book but I guess it is more convenient to include the picture here. If I do violate the copyright please let me know and I am happy to remove the picture.

However, I got the following picture instead.

The graph of $f(x)=x^a\sin(x^{-b})$ for $a=1/2$ and $b=1$

I use the following code

\begin{center}

\begin{tikzpicture}

\draw[smooth, thick, domain=1/100:2*pi] plot (\x, {\x^(0.5)*sin(deg(\x^(-1)))});

\end{tikzpicture}

\end{center}

I tried different values of a and b as described in the book, but doesn't work. Is the domain wrong or I should use other commands?

Thanks for your help.

  • Welcome to TeX.SX! One thing to note is that the default number of samples within the domain is 25, which means that a lot of the high frequency variability will not be visible. Try adding e.g. ,samples=1000 after the domain specification. – Torbjørn T. Jan 24 '17 at 12:02
8

Using LuaLaTeX and the PGFPlots package you could do the following, which is almost what you want I think ...

% used PGFPlots v1.14
\RequirePackage{luatex85}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{
        groupplots,
    }
    \pgfplotsset{
        compat=1.12,
        /pgf/declare function={
            f(\a,\b,\x) = \x^(\a)*sin(deg(\x^(-1*\b)));
        },
    }
\begin{document}
    \begin{tikzpicture}
        \begin{groupplot}[
            group style={
                group size=1 by 3,
                vertical sep=2mm,
            },
            height=3cm,
            width=6cm,
            xtick=\empty,
            ytick=\empty,
            ymin=-0.5,
            ymax=0.5,
            axis lines=center,
            domain=0:0.4,
            samples=1001,
            no markers,
            /tikz/smooth,
        ]
        \nextgroupplot
            \addplot {f(2,1,x)};
            \node [anchor=north] at (axis description cs:0.5,1) {$a=2$, $b=1$};
        \nextgroupplot
            \addplot {f(1,1,x)};
            \node [anchor=north] at (axis description cs:0.5,1) {$a=1$, $b=1$};
        \nextgroupplot
            \addplot {f(0.5,1,x)};
            \node [anchor=north] at (axis description cs:0.5,1) {$a=1/2$, $b=1$};
        \end{groupplot}
    \end{tikzpicture}
\end{document}

image showing the result of above code

4

We can parametrize the x values to concentrate the data points where they are needed : close to 0.

Then we add a filled cap to the left.

Output

enter image description here

Code

\documentclass[tikz, border=10pt]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
  [
    declare function=
    {
      t(\x) = 1/\x ;
    }
  ]
  \begin{axis}
    [
      samples=2000,
      axis lines=center,
      xtick=\empty,
      ytick=\empty,
      extra y ticks={0},
    ]
    \addplot[domain=1:60,semithick] ({t(\x)},{sqrt(t(x))*sin(deg(1/t(x)))});
    \addplot[domain=-.14:.14,semithick,samples=100, area style, fill=black] ({x^2},{x}) \closedcycle;
  \end{axis}
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.