1

I am trying to plot the function $-0.5x^{\frac{4}{3}}-x^{\frac{1}{3}}+1.2x+1$ over the interval $[-2,5]$ but the graph for negative $x$ values is not plotting. How do I get the graph when $x$ is negative?

\begin{tikzpicture}

\begin{axis}[ axis lines = center, xlabel = $x$, ylabel = $y$, xmin = -2.5, xmax = 4.5, ymin = -1.5, ymax = 2.5, xtick = {-2,-1.191,-0.103,0,0.292,1,2,4.144}] \addplot[ domain = -5:5, samples = 200, smooth, thick, blue, ] {-0.5x^(4/3)-x^(1/3)+1.2x+1}; \end{axis}

\end{tikzpicture}

2 Answers2

4

This question has been raised before several times (1, 2, 3, 4). The problem seems to lie in the way PGF deals with roots and fractional powers using logarithmic functions. (For more details, see this question.)

As suggested by the author of this answer, you can use the expression x/abs(x)*abs(x)^(1/3) to replace x^(1/3) in order to circumvent the above problem. You would then get:

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

\begin{document} \begin{tikzpicture}

\begin{axis}[ axis lines = center, xlabel = $x$, ylabel = $y$, xmin = -2.5, xmax = 4.5, ymin = -1.5, ymax = 2.5, xtick = {-2,-1.191,-0.103,0,0.292,1,2,4.144}, x post scale=2] \addplot[ domain = -5:5, samples = 200, smooth, thick, blue, ] {-0.5x/abs(x)abs(x)^(4/3)-x/abs(x)abs(x)^(1/3)+1.2x+1}; \end{axis}

\end{tikzpicture} \end{document}

enter image description here

  • 1
    Note that the left half might be wrong here. I get a negative answer when I pass in -1. This worked: \pgfmathdeclarefunction{CubeRoot}{1}{% \pgfmathparse{ifthenelse(#1<0,-1,1)*exp((ln(abs(#1)))/3)}% } – Ungar Linski Oct 27 '21 at 00:32
0
\documentclass[border=1 cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
 \begin{axis}[
    axis lines = center,
    xlabel = $x$,
    ylabel = $y$,
    xmin = -2, xmax = 6,
    ymin = -1.5, ymax = 2.5,
    x tick label style={/pgf/number format/precision=3},
    xtick = {-2,-1.191,-0.103,0,0.292,1,2,4.144},
    x post scale=4,
]
    \addplot[
        domain = -2:6,
        samples = 200,
        smooth,
        thick,
        blue,
    ] {-0.5*x^(4/3)-x^(1/3)+1.2*x+1};
\end{axis}
\end{tikzpicture}
\end{document}

Very wide graph