[pstricks] graphing the cube root function (part 2)

Herbert Voss LaTeX at zedat.fu-berlin.de
Thu Aug 25 21:34:43 CEST 2005


Ryan Higginbottom wrote:
> Let me explain myself a bit more.
> 
> I am unable to graph the cube root function for negative x-values.  A
> minimal example:
> 
> \documentclass{article}
> \usepackage{pstricks,pst-plot,pstricks-add}
> \begin{document}
> \psplot[algebraic=true,plotpoints=200]{-5}{5}{x^(1/3)}
> \end{document}
> 
> Am I missing something obvious?

a problem with the PostScript power function exp
The easiest way is

\psplot[algebraic,plotpoints=200]{-5}{0}{-(-x)^(1/3)}
\psplot[algebraic,plotpoints=200]{0}{5}{x^(1/3)}

a more elegant way:

\psplot[plotpoints=200]{-5}{5}{x abs 1 3 div exp x 0 lt {neg}if}

or with algebraic option:

\psplot[plotpoints=200,algebraic]{-5}{5}{IFTE(x<0,-abs(x)^(1/3),x^(1/3))}


Herbert




More information about the PSTricks mailing list