5

I'm trying to plot the graph (x+2)^{1/2}(x-7)^{2/3}, using the code below, but after compiling the axis is present, but the plot is empty. Could anyone point out what I am missing? Any assistance would be appreciated. Thank you!

\begin{tikzpicture}[thick]
\begin{axis}[
    axis lines = center,
    legend pos = outer north east,
    xlabel = $x$,
    ylabel = $y$,
]
%Below the red parabola is defined
\addplot [
    domain=-5:5, 
    samples=100, 
    color=red,
]
{(x+2)^(1/3)*(x-7)^(2/3)};
\end{axis}
\end{tikzpicture}
cmhughes
  • 100,947

1 Answers1

6

As detailed in Pgfplots : can't plot some usual mathematical functions, the problem is that cube roots and other fractional powers are computed using logarithmic functions; as such, you can not produce (x-2)^(1/3) directly for negative numbers, but you can use

abs(x-2)/(x-2)*abs(x-2)

which is fine, provided that x\ne 2.

enter image description here

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[thick]
    \begin{axis}[
            axis lines = center,
            legend pos = outer north east,
            xlabel = $x$,
            ylabel = $y$,
        ]
        %Below the red parabola is defined
        \addplot [
            domain=-5:5,
            samples=100,
            color=red,
        ]
        {abs(x+2)/(x+2)*abs((x+2))^(1/3)*abs(x-7)/(x-7)*abs(x-7)^(2/3)};
    \end{axis}
\end{tikzpicture}
\end{document}
cmhughes
  • 100,947