# How to plot the function the absolute value of x*(x-1)^(1/3) using tikzpicture environment

I am trying to plot f(x)=abs(x*(x-1)^(1/3)) on [0,2]:

I have to use tikzpicture environment but I am not able to do it in a nice way.

MWE:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

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

\begin{center}
\begin{tikzpicture}[declare function={f(\x)=ifthenelse(\x>=0&&\x<=1,abs(\x*(\x-1)^(1/3)),\x*(\x-1)^(1/3));}]
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]
\end{axis}
\end{tikzpicture}
\end{center}


The same effect is produced if I try with \addplot[very thick,red,samples=81,domain=0:2,name path=f] {abs(x*(x-1)^(1/3))};:

\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]
\end{axis}
\end{tikzpicture}
\end{center}


Thanks and have a nice 2019!

• Your document is incomplete – user31729 Jan 1 at 0:02

You set the brackets in such a way that the compiler sees (x-1)^(1/3). It does not know how to plot the third root of a negative number, and let's it be. I fixed the brackets to obtain

\documentclass{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{center}
\begin{tikzpicture}[declare function={f(\x)=ifthenelse(\x>=0&&\x<=1,\x*abs(\x-1)^(1/3),\x*(\x-1)^(1/3));}]
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]
\end{axis}
\end{tikzpicture}
\end{center}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis on top,
legend pos=outer north east,
axis lines = center,
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
legend style={cells={align=left}},
legend cell align={left},
]

• It is? You know I thought about it while taking a shower but for the time zones I said "There is no way it is the first question of 2019" :D. If so, you are the first best answer of 2019 ;). – manooooh Jan 1 at 0:44