2

TikZ seems to graph the cube root function with the code provided - on the positive x-axis. Why isn't TikZ plotting the whole graph?

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-10,xmax=10,
    domain=-10:10, samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-2.5,ymax=2.5,
    restrict y to domain=-2.5:2.5,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=-10:10,blue] {x^(1/3))} node[above,pos=0.9]{$\scriptstyle{y} = f(x)$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}
Adelyn
  • 3,373
  • 2
    Probably because of the mathematical definition of x^{1/3}: exp(ln(x)/3). That's the way it is defined in any pocket calculator. – Bernard Oct 12 '14 at 00:29
  • @Bernard Thanks for the information. How do I get a plot of the cube root function? – Adelyn Oct 12 '14 at 00:37
  • 1
    Make two plots: one between -10 and -0.0001, say, of -(-x)^(1/3), and one between 0.0001 and 10 of x^(1/3). Not sure how tikz works, but mathematically, you'll have problems at 0, hence the very small but non zero values. However if tikz has a sign and an abs function (I don't know: personally I do these things with pstricks), it might be simpler to plot sgn(x)(abs(x))^(1/3)between -10 and 10. – Bernard Oct 12 '14 at 00:48
  • 2
  • @Bernard I graphed -(-x)^(1/3) on the interval [-10, -0.0001] and it looks fine. Thanks. I graphed (abs(x))^{1/3} on the interval [-10, 10] and only the cube root function on the positive x-axis was plotted. I thought abs was the code for absolute value function. – Adelyn Oct 12 '14 at 15:58
  • @Adelyn/ It seems that it is the code , but I've seen this coded as abs(\x) (with a backslash for the variable). As I said, I really don't know tikz (I only use tikz-cd, with is a quite different thing from plotting functions. Let me add that you can plot your function in one stroke if you know how to plot parametric curves (it's the curve x=t³, y=t), but you'll have to compute the bounds that correspond to x = –10 and x = 10. – Bernard Oct 12 '14 at 16:27
  • 1
    Another approach would be to compute a Talor's series or use successive approximation. But Tikz actually uses lookup tables for all the nonlinear math functions, so simply constructing an array of values and importing into LaTeX is ultimately the best approach. – John Kormylo Oct 12 '14 at 19:51

0 Answers0