# How to make Derive work with a parameter other than x and how to invoke Derive in postfix notation?

In my investigation Derive can only evaluate the derivative of function f(x) with respect to x. My attempt below does not produce the expected result because I try to find the derivative of x(t) and y(t) with respect to t.

\documentclass{article}
\usepackage{pst-plot,pst-node}

\def\x{sin(t)}
\def\y{cos(t)}

\def\xx{Derive(1,\x)}
\def\yy{Derive(1,\y)}

\begin{document}

\begin{pspicture}[algebraic](-.2,-2.2)(\dimexpr\psPiFour cm+.2cm,2.2)
\psparametricplot{0}{TwoPi 2 mul}{\xx|\yy}
\end{pspicture}

\end{document}

• Can anybody here help me to let Derive also work with any variable such that my project here (click) can be easily done without having to manually calculate the derivative of the given functions?

• How can we invoke Derive in postfix form? If it is possible then the first question can be solved just by using ED as follows,

<postfix expression in x>  1 Derive t /x ED


## 1 Answer

The variable x used for the derivative is hardcoded, see definition of /EvalDerive in the file pst-algparser.pro. So you must redefine some internal Postscript functions.

The less invasive redefinition I found was to change /EvalVariable, which is the only procedure actually accessing the (x):

\documentclass[pstricks,margin=5pt]{standalone}
\usepackage{pst-plot,pst-node}
\def\ChangeEvalVariable#1{%
\pstVerb{tx@Derive begin
/origEvalVariable /EvalVariable load def
/EvalVariable { 2 index (#1) eq { (1) } { (0) } ifelse 4 -1 roll exch 6 2 roll } def
end }%
}%
\def\ResetEvalVariable{%
\pstVerb{tx@Derive begin
/EvalVariable /origEvalVariable load def
end }%
}%
\def\x{sin(t)}
\def\y{cos(t)}

\def\xx{Derive(1,\x)}
\def\yy{Derive(1,\y)}

\begin{document}

\begin{pspicture}[algebraic](-1.2,-1.2)(3.2,1.2)
\ChangeEvalVariable{t}
\psparametricplot{0}{Pi}{\xx|\yy}
\ResetEvalVariable
\psplot{0}{Pi}{Derive(1,sin(x))}
\end{pspicture}

\end{document} You cannot use Derive for a Postscript expression, because Derive actually calculates the derivative analytically by parsing the string representation of the function.