# PGFplot of sqrt x error

I'm trying to plot the square and cubic root of x using this code:

\begin{tikzpicture}[scale=.5, >=stealth]

\begin{axis}[
xmin=-5,xmax=5,
ymin=-5,ymax=5,
axis x line=middle,
axis y line=middle,
axis line style=<->,
]
node[pos=0.65,anchor=south west]{$y=\sqrt{x}$};

node[pos=0.65,anchor=south west]{$y=\sqrt[3]{x}$};
\end{axis}
\end{tikzpicture}


but I get the following errors:

I've tried writing \sqrt instead of sqrt but the errors are the same. How can I solve this?

Ok so, trying, as suggested by a comment, to try different formulas I got it working with x^(1/2) and x^(1/3)

The problem now is that I get the wrong graph for the cube root.

The code now is:

             \begin{tikzpicture}[scale=.5, >=stealth]

\begin{axis}[
xmin=-5,xmax=5,
ymin=-5,ymax=5,
axis x line=middle,
axis y line=middle,
axis line style=<->,
]
node[pos=0.65,anchor=south west]{$y=\sqrt{x}$};

node[pos=0.65,anchor=south west]{$y=\sqrt[3]{x}$};
\end{axis}
\end{tikzpicture}


But for the cube root I'm missing the negative branch:

How can I solve this?

• Have you tried with sqrt(x) with the rounded bracket. This is the correct syntax. Sep 28, 2020 at 21:35
• Yes. It didn't work neither but it worked when I used x^(1/2) and x^(1/3). Though for the latter it gives the wrong graph. Sep 28, 2020 at 21:38
• Try with sqrt(x) and exp(ln(x)/3) for the square and cubic root. Please, can you put your complete MWE? Just for me there are some mistakes to compile it. See after also this link: tex.stackexchange.com/questions/19052/… Sep 28, 2020 at 21:49
• @downvoter: Reason of downvote please!!
– user108724
Sep 29, 2020 at 9:35
• @Sebastiano: Thanks a lot. :).
– user108724
Sep 29, 2020 at 9:40

I don't really know why TikZ can't plot correctly but here is a trick: graph of x^(1/3) is same as (x^3,x) (if I am not mistaken):

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[scale=1, >=stealth]

\begin{axis}[
xmin=-5,xmax=5,
ymin=-5,ymax=5,
axis x line=middle,
axis y line=middle,
axis line style=<->,
]
node[pos=0.65,anchor=south]{$y=\sqrt[3]{x}$};

• (x,y=x^1/3)=(y^3,y).