# [pstricks] A little bit more complicated function definition fails again. Was: Can't use a mathematical function defined with FPeval in \psplot

Juergen Rose rose at rz.uni-potsdam.de
Tue Apr 15 14:01:54 CEST 2014

Am Dienstag, den 15.04.2014, 11:15 +0200 schrieb Herbert Voss:
> Am 14.04.2014 07:52, schrieb Juergen Rose:
...
> it makes no sense to define a function inside a PostScript
> context. Use
>
> usepackage[nomessages]{fp}
> \usepackage{pst-plot}
> \def\Vre{700}
>
> \begin{document}
>
> \edef\nonr#1{1000*(\Vre/2)^(1/3)/((2)^0.5*(#1))+(6)^0.5/2-1}
> \def\myMathFunction#1{(\nonr{(#1)}) * 5 - (\nonr{(#1)})^2}
>
> \pspicture[shift=*](-1,0)(6,7)
> \psaxes{->}(5.5,6)
> \psplot[algebraic,linecolor=red,linewidth=1.5pt]{1}{5}{%
>   \myMathFunction{x}%
> }
> \endpspicture
> \end{document}
>
> Herbert

That works again perfectly. I modified this a little bit and this works
too:

\documentclass{article}
\usepackage[nomessages]{fp}
\usepackage{pst-plot}

\def\Vre{350}

\begin{document}

\edef\nonr#1#2{2*((#2)/2)^(1/3)/((2)^0.5*(#1))+(6)^0.5/2-1}
\def\myMathFunction#1#2{(\nonr{(#1)}{(#2)}) * 5 - (\nonr{(#1)}{(#2)})^2}

%\FPeval\myMathFuncTwo{\myMathFunction{2}{(\Vre{})}}
\def\myMathFuncTwo{3.5}

\pspicture[shift=*](-1,0)(15,7)
\psaxes{->}(14.5,7.5)
\psline[linecolor=red](0,0.5)(2,0.5)
\psline[linecolor=red](2,0.5)(2,\myMathFuncTwo)
\psplot[algebraic,linecolor=red,linewidth=1.5pt]{2}{5}{%
\myMathFunction{x}{\Vre}%
}
\psplot[algebraic,linecolor=red,linewidth=1.5pt]{5}{14}{%
\myMathFunction{x}{\Vre}%
}
\endpspicture
\end{document}

But if I remove the fixed value for myMathFuncTwo{3.5} an try to use the
calculated value FPeval\myMathFuncTwo{\myMathFunction{2}{(\Vre{})}}:

\documentclass{article}

\usepackage[nomessages]{fp}
\usepackage{pst-plot}

\def\Vre{350}

\begin{document}

\edef\nonr#1#2{2*((#2)/2)^(1/3)/((2)^0.5*(#1))+(6)^0.5/2-1}
\def\myMathFunction#1#2{(\nonr{(#1)}{(#2)}) * 5 - (\nonr{(#1)}{(#2)})^2}

\FPeval\myMathFuncTwo{\myMathFunction{2}{(\Vre{})}}

\pspicture[shift=*](-1,0)(15,7)

\psaxes{->}(14.5,7.5)
\psline[linecolor=red](0,0.5)(2,0.5)
\psline[linecolor=red](2,0.5)(2,\myMathFuncTwo)
\psplot[algebraic,linecolor=red,linewidth=1.5pt]{2}{5}{%
\myMathFunction{x}{\Vre}%
}
\psplot[algebraic,linecolor=red,linewidth=1.5pt]{5}{14}{%
\myMathFunction{x}{\Vre}%
}
\endpspicture
\end{document}

it fails with:

(/usr/share/texmf-dist/tex/generic/pst-plot/pst-plot.tex
v1.45, 2013/04/29 (tvz,hv)))
(./define_math_function_test_4__fp_table_plot.aux
)
! Missing $inserted. <inserted text>$
l.13 ...yMathFuncTwo{\myMathFunction{2}{(\Vre{})}}

The real function, I want to plot, is at least 3 times longer and has
more parameters than the function used here. The real function has a
similar shape, i.e. it starts with constant, than it jumps to higher
value, continues with a sharp peak and ends with a long tail (An example
is in the attachment). I.e., I need the function three times, 1st for
vertical line connected with the jump, 2nd for the sharp peak and third
for the long tail. To avoid errors in modifying three occurrence of the
function. I would prefere to define the function once and modify only
this definition. Sometimes it would be furthermore good to print some
values of the function in a table. Herbert, can I bother you once more

Juergen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: surface_206.pdf
Type: application/pdf
Size: 74113 bytes
Desc: not available
URL: <http://tug.org/pipermail/pstricks/attachments/20140415/b60e9df3/attachment-0001.pdf>