# Drawing the graph of a complicated function

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.

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.

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?

• 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

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
\node [anchor=north] at (axis description cs:0.5,1) {$a=2$, $b=1$};
\nextgroupplot
\node [anchor=north] at (axis description cs:0.5,1) {$a=1$, $b=1$};
\nextgroupplot
\node [anchor=north] at (axis description cs:0.5,1) {$a=1/2$, $b=1$};
\end{groupplot}
\end{tikzpicture}
\end{document}


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.

## 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},
]