# geometric transformations

Denis Girou Denis.Girou at idris.fr
Thu Apr 23 22:11:02 CEST 1998

-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

Rick.Hensh> Perhaps someone can help. It is easy to use PSTricks and specials to graph
Rick.Hensh> the function,
Rick.Hensh> say
Rick.Hensh>
Rick.Hensh> y = f[x]
Rick.Hensh>
Rick.Hensh> For example, if f[x] = x*(1-x) I've successfully tried
Rick.Hensh>
Rick.Hensh> \special{!/myfunction {x dup 1 exch sub mul} bind def}
Rick.Hensh> \psplot[myparem]{-5}{5}{myfunction}
Rick.Hensh>
Rick.Hensh> Now I would like to sketch    y = f[x-2]     by trying something like
Rick.Hensh>
Rick.Hensh> \psplot[myparem]{-5}{5}{x 2 sub myfunction}

Thomas.Siegel> you should define your function in a different way. Here is a little
Thomas.Siegel> example:

Thomas.Siegel> \documentclass{article}

Thomas.Siegel> \usepackage{pstricks}
Thomas.Siegel> \usepackage{pst-plot}

Thomas.Siegel> \begin{document}

Thomas.Siegel> \psset{yunit=.5cm}

Thomas.Siegel> \special{!/myfunction {dup 1 exch sub mul} bind def}

Thomas.Siegel> \begin{pspicture}(-5,-30)(5,1)\psgrid
Thomas.Siegel> \psplot[linecolor=red]{-5}{5}{x myfunction}
Thomas.Siegel> \psplot[linecolor=green]{-3}{5}{x 2 sub myfunction}
Thomas.Siegel> \end{pspicture}

Thomas.Siegel> \end{document}

The answer of Thomas is obviously correct and correspond to your
requirement. Nevertheless, in the general case, with a more complicated
definition of the function, it will be more difficult to follow this way.

A more general solution is to use a macro definition. In this case, you
can use PostScript in a similar way that you use LaTeX, redefining later
locally or globally a defined macro.

\documentclass{article}

\usepackage{pst-plot}

\pagestyle{empty}

\begin{document}

\psset{yunit=0.5,subgriddiv=0}

\special{! /vx {x} def
/myfunction {vx 1 vx sub mul} def}

\begin{pspicture}(-5,-30)(5,1)\psgrid
\psplot[linecolor=red]{-5}{5}{myfunction}
\psplot[linecolor=green]{-3}{5}{/vx {x 2 sub} def myfunction}
\end{pspicture}

\begin{pspicture}(-5,-30)(5,1)\psgrid
\psplot[linecolor=red]{-5}{5}{myfunction}
\psplot[linecolor=green,plotpoints=101]{-5}{5}{/vx {x abs sqrt} def myfunction}
\end{pspicture}

\end{document}

D.G.

-----------------------------------------------------------------------------