# How to plot functions involving rational exponents using pgfplots?

The power functions that i'm trying to plot isn't showing up fully, i've tried changing the domains and stuff but to no avail, can i get some help here please?

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {4},
xmin = {-1},
ymax = {2},
ymin = {-2},
legend pos = outer north east
]
domain=-10:10,
samples=100,
color=black,
]
{x^(1/2)};
\addlegendentry{$y=\sqrt{x}$}
domain=-5:5,
samples=100,
color=blue,
]
{x^(1/4)};
\addlegendentry{$y=x^{\frac{1}{4}}$}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {4},
xmin = {-4},
ymax = {2},
ymin = {-2},
legend pos = north west
]
domain=-10:10,
samples=100,
color=black,
]
{x^(1/3)};
\addlegendentry{$y=x^{\frac{1}{3}}$}
domain=-10:10,
samples=100,
color=blue,
]
{x^(1/5)};
\addlegendentry{$y=x^{\frac{1}{5}}$}
\end{axis}
\end{tikzpicture}
\end{document}

• Please make it compilable by adding document class and packages required. Welcome. – Jesse Feb 8 '16 at 4:20
• Welcome to TeX.SE. As Jesse said, It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. I would recommend you use (x) instead of just x. Otherwise I get two graphs output. Also, please clarify what you mean by "showing up fully". – Peter Grill Feb 8 '16 at 4:25
• My apologies, i've edited it accordingly. By not showing up fully, i mean that the graphs of y=x^(1/3) and y=x^(1/5) are not showing up at the 3rd quadrant as it is supposed to. – Tay Yong Qiang Feb 8 '16 at 4:32
• Try using (x) instead of x and PGF Math Function to compute cube root may be of help. – Peter Grill Feb 8 '16 at 5:12
• @cmhughes: Yes it is that simple, but that is assuming one can read the code. I can actually relate to the OPs difficulties as it often takes me several guesses as to where to make slight changes to some of the expl3 solutions I am using. Similarly, when it comes to expansion issues. Also, there was a bizarre issue of the 2nd plot needing a \hspace*{-23.5cm} to be able to see it -- see the edit history. Jake rescued me on that one so no longer an issue. – Peter Grill Feb 8 '16 at 22:01

You can adapt the solution from PGF Math Function to compute cube root to generate a function that computes the third and fifth root:

## Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}

\pgfmathdeclarefunction{CubeRoot}{1}{%
\pgfmathparse{ifthenelse(#1<0,-1,1)*exp((ln(abs(#1)))/3)}%
}

\pgfmathdeclarefunction{FifthRoot}{1}{%
\pgfmathparse{ifthenelse(#1<0,-1,1)*exp((ln(abs(#1)))/5)}%
}

\begin{document}\noindent
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = {4},
xmin = {-1},
ymax = {2},
ymin = {-2},
legend pos = south east
]
domain=0:4,
samples=100,
color=orange,
line width=1.0pt,
]
{(x)^(1/2)};
\addlegendentry{$y=\sqrt{x}$}
domain=0:5,
samples=100,
color=blue,
line width=1.0pt,
]
{(x)^(1/4)};
\addlegendentry{$y=x^{\frac{1}{4}}$}
\end{axis}
\end{tikzpicture}
\par
\noindent
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
xlabel = $x$,
ylabel = {$y$},
xmax = 4,
xmin = -4,
ymax = 2,
ymin = -2,
legend pos = south east,
clip=true,
]
domain=-4:4,
samples=100,
color=blue,
line width=1.0pt,
]
{CubeRoot(x)};
\addlegendentry{$y=x^{\frac{1}{3}}$}
\addlegendentry{$y=x^{\frac{1}{5}}$}

• @Jake: Thanks. That was quite the space for a missing %. Whatever happened to multiple spaces are treated as a single space? :-) – Peter Grill Feb 8 '16 at 8:38