# pgfplots fails to graph the function [sin(x)]^100

The image shows that the graph of [sin(x)]^100 (in red) lies below the x-axis in four small intervals, as the function is non-negative its graph should be on or above the x-axis. So there is an error when plotting the graph of [sin(x)]^100, but I have no idea how to correct it.

I would appreciate anyone willing to point me to a solution or paths to it.

The image was generated with the code

\documentclass[a4paper]{scrbook}
\usepackage{xcolor}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[xscale=1.5,axis x line=bottom,axis y line=left,
axis x line=middle,axis y line=middle,xmax=6.7,ymax=1.3,
every inner x axis line/.append style={-
stealth},xlabel=$x$,ylabel=$f_n(x)$,]
\end{axis}
\end{tikzpicture}

\end{document}


Source of your problem is use smooth (spline function) on too small number of sampled. So, if you:

• increase number od samples, for example to 401,
• remove smooth instruction,
\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = middle,
xmax=6.7,   ymax=1.3,
xlabel=$x$, ylabel=$f_n(x)$,
%
clip=false,
legend style = {at ={(0.8,0.8)}, anchor=west,
font=\scriptsize,
legend cell align=left,
},
%
domain=0:2*pi,  samples=401,
no marks,
]

\legend{$\sin(x)$, $(\sin(x))^{100}$}
\end{axis}
\end{tikzpicture}
\end{document}


you will get desired result:

Off-topic:

• clear-up axis preamble (too many axis instructions where the last ones overwrite the first ones)
• move common option from addplot to axis preamble

Edit (1): To diagram is added legend.

Edit (2): A version of your diagram where x ticks are given in radians and function curves are thicker (for exercise):

\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
x = 12mm,
axis lines = middle,
xmax=7,   ymax=1.4,
xlabel=$x$ (rad), ylabel=$f_n(x)$,
% legend
clip=false,
legend style = {at ={(0.8,0.8)}, anchor=west,
font=\scriptsize,
legend cell align=left,
},
% new
xtick = {pi/4,    pi/2,     3*pi/4,   pi,
5*pi/4, 3*pi/2,    7*pi/4,  2*pi},
xticklabels = {$\pi/4$, $\pi/2$, $3\pi/4$, $\pi$,
$5\pi/4$, $3\pi/2$, $7\pi/4$, $2\pi$},
tick label style = {font=\footnotesize},
x tick label style = {yshift=-2ex, anchor=center},
extra y ticks = {0},
%
domain=0:2*pi,  samples=401,
no marks,
every axis plot post/.append style={thick},
]

\legend{$\sin(x)$, $(\sin(x))^{100}$}
\end{axis}
\end{tikzpicture}
\end{document}


• Off-topic: for large n, (sin x)^n is very very close to exp(n (x-pi/2)^2/2). This can help for easier plotxand computation.
– Jhor
Aug 1 at 8:01

Try adding samples=100 to your code for sin(x)^100, it should fix the problem. This is the new code:

begin{tikzpicture}
\begin{axis}[xscale=1.5,axis x line=bottom,axis y line=left,
axis x line=middle,axis y line=middle,xmax=6.7,ymax=1.3,
every inner x axis line/.append style={-
stealth},xlabel=$x$,ylabel=$f_n(x)$,]