# How to define a mathematical equation in two parameters in PSTricks?

I am to draw a 3D function, using PSTricks' \parametricplotThreeD. Coordinate Z in two parameters is so awkward, in terms of controlling boundary values and formulation that I decided to break it into the affordable functions.

For the mathematical function (as an example),

f(t, u) = (1-u)cos(t) + uSin(t/3),


I used some of the tex.stackexchange questions and defined my function as, e.g.,

\documentclass{minimal}

\usepackage{pstricks}

\usepackage{pst-solides3d}%Drawing
\usepackage{pst-3dplot}%

\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp

\begin{document}

\newcommand{\fMathFunction}
{\FPeval\result{(1-#2)(cos(#1)) + (#2)(sin((#1)/3))}\result}.

\parametricplotThreeD[algebraic, xPlotpoints=20,
linecolor=blue,%
linewidth=0.5pt,plotstyle=curve](0, 1)(0, 1){%
t|\fMathFunction{t}{u}|2+sqrt(\fMathFunction{t}{u})}%

\end{pspicture}
\end{document}


I get alot af errors.

I would like to know if defining a function in two variables is possible and how it can be utilised. If I moved, then, additionally I like to define another function, say,

g(t, u) = 2 + sqrt (f(g, u)),


and use it in place of Z.

Edit 1: My goal in this question is not drawing. I like to know if it is possible to define a custom mathematical function in two variables. We already know how to define a custom f(x). I like to define a custom f(x,y).

• I assume your last expression should be g(t,u) = 2 + sqrt(f(t,u)). Do you have a graphic of what the function should look like? – Werner Jan 12 '16 at 20:10
• Never use the minimal class, see Why should the minimal class be avoided? – egreg Jan 13 '16 at 21:58
• @egreg: for PSTricks it makes offen sense to use the minimal class! – user2478 Jan 13 '16 at 22:01
• @Herbert I don't think so. – egreg Jan 13 '16 at 22:02
• My class, actually, is \documentclass[makeidx]{amsbook}. I meant to give a minimal example here. – Peter Jones Jan 14 '16 at 11:38

I do not see how g(t,u) = 2 + sqrt(f(t,u)) should work with 0..1. f(t,u) can be negative. However, no need for the parametric function:

\documentclass{article}
\usepackage{pst-solides3d}
\begin{document}

\psset{viewpoint=30 -50 30 rtp2xyz,Decran=50,lightsrc=viewpoint}
\begin{pspicture}(-1,-1)(3,7.5)
\psSolid[object=grille,base=0 3 0 3,action=draw]
\psSurface[ngrid=.1 .1,incolor=yellow,axesboxed,Zmin=-2,Zmax=4,
linewidth=0.5\pslinewidth,
algebraic,hue=0 1](0,0)(3,3){(1-y)*cos(x)+y*sin(x/3)}
\end{pspicture}

\end{document} or with a defined function:

\def\myFunction(#1,#2){(1-#2)*cos(#1)+#2*sin(#1/3)}
\psset{viewpoint=30 -50 30 rtp2xyz,Decran=50,lightsrc=viewpoint}
\begin{pspicture}(-1,-1)(3,7.5)
\psSolid[object=grille,base=0 3 0 3,action=draw]
\psSurface[ngrid=.1 .1,incolor=yellow,axesboxed,Zmin=-2,Zmax=4,
linewidth=0.5\pslinewidth,
algebraic,hue=0 1](0,0)(3,3){\myFunction(x,y)}
\end{pspicture}

• I am honoured getting answer directly from Herbert. Nevertheless my question is to put a function myFunction(x,y) defined at the top and then plugged into as (0,0)(3,3){myFunction(x,y)} instead of explicit expression (0,0)(3,3){(1-y)*cos(x)+y*sin(x/3)}. – Peter Jones Jan 14 '16 at 11:33
• \def\myFunction(#1,#2){(1-#2)*cos(#1)+#2*sin(#1/3)} See edited answer – user2478 Jan 14 '16 at 11:40