Graphics, Figures & Tablespst-plot and the exponential function

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

pst-plot and the exponential function

Post by Bozack »

Hi

I'm trying to plot a rather complex function with pst-plot with PSTricks. I use the pst-infixplot package, since I am not very fond of the reverse polish notation. But I get a weird error every time I try to plot the part of the function containing an exponential.

Even if I try to plot the exponential function exp(x), the error shows up. It says
Syntax error: Garbage after parenthesis
I've attached a test-file which makes the error, including the preamble I use. I hope someone can see why this error shows up... :(
Attachments
test.log
The log-file of a compilation
(15.93 KiB) Downloaded 387 times
test.tex
The file I need compiled
(2.02 KiB) Downloaded 423 times
Last edited by Bozack on Sun May 03, 2009 3:26 pm, edited 1 time in total.
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

fatra2
Posts: 126
Joined: Fri May 01, 2009 1:43 pm

Re: pst-plot and the exponential function

Post by fatra2 »

Hi there,

Could you enlighten me on pst-plot? Is it a plot software that outputs into postscript?

If so, I would recommend to try gnuplot (work on Windows very well, and it's free of charge). With it, you will be able to make wonderful plot in 2D or 3D. The function can be as complicated as you want, the plots will always looking very professional.

Hope I could give you a hand. Cheers
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

pst-plot and the exponential function

Post by Bozack »

fatra2 wrote:Could you enlighten me on pst-plot? Is it a plot software that outputs into postscript?
Yes, pst-plot is part of the PSTricks family - made for plotting things (read: functions, data etc.) by using the PostScript language. You can read more about PSTricks at http://tug.org/PSTricks/main.cgi/. And you can read more about the pst-plot package at http://math.mercyhurst.edu/~griff/TeX/p ... otting.pdf.
fatra2 wrote:I would recommend to try gnuplot.
I already know GnuPlot - and use it both on Windows and Linux - but I like pst-plot better because I think the output turns out prettier by less work.

My problem with the exponential function in temporarily used by simply writing

Code: Select all

2,718^(blabla)
instead of trying to write

Code: Select all

exp(blabla)
But I would still like to know why the error turns up when I try to use the second of these two. The exponential function should work just as nicely as sin, cos etc.?
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pst-plot and the exponential function

Post by localghost »

There is no reason to change to Gnuplot. The cause of the error is that you have forgotten the algebraic option for plot command. Moreover you can't sue the exp expression but you have to use a value for the Euler number.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage{pstricks-add}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \small
    \psset{llx=-1.25cm,lly=-1cm,urx=1mm,ury=1mm}
    \psset{xAxisLabel={$x$-Axis},xAxisLabelPos={4,-3},yAxisLabel={$y$-Axis},yAxisLabelPos={-3.25,7}}
%    \psframebox[linestyle=dashed,linewidth=0.4pt]{%
    \begin{psgraph}[Dx=1,Dy=1,Ox=-2,Oy=-1,subticks=5,ticksize=0pt 4pt](-2,-1)(-2,-1)(10,15){10.5cm}{7.5cm}
      \psaxes[Dx=1,Dy=1,Ox=-2,Oy=-1,subticks=5,labels=none,ticksize=-4pt 0](10,15)(-2,-1)(10,15)
      \psplot[algebraic,linecolor=red]{-1.825}{10}{(1-(4/3)*x+(8/27)*x^2)*2.718^(-(2/3)*x)}
    \end{psgraph}
%    }
    \caption{A nice plot with \textsf{PSTricks}.}\label{fig:pstplot}
  \end{figure}
\end{document}
I have used the psgraph environment to get a better result. The \psframebox is for checking the right trim values (llx, lly, urx, ury). These and all other options are described in detail in the pstricks-add manual.

Abandon the dvips driver for the document class or any other package that could use it. Current versions of those packages detect on their own which compiler is running and then load the right driver.


Best regards
Thorsten¹
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

pst-plot and the exponential function

Post by Bozack »

localghost wrote:The cause of the error is that you have forgotten the algebraic option for plot command.
I didn't know that option - I've always just used the pst-infixplot package to be able to use normal algebraic notation instead of the reverse polish notation. Thanks for the tip!
localghost wrote:Moreover you can't use the exp expression but you have to use a value for the Euler number.
I still think this is kind of weird - that the exp expression is not defined anywhere, and I hence have to use the Euler number... I figured this out myself as a quick fix, but to me it doesn't seem right (I think it's easier to remember the expression exp than the number 2.718).
localghost wrote:I have used the psgraph environment to get a better result.
I've never used that environment - nice to get a little hands-on example. Thanks for that.
localghost wrote:Abandon the dvips driver for the document class or any other package that could use it. Current versions of those packages detect on their own which compiler is running and then load the right driver.
Okay :D
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pst-plot and the exponential function

Post by localghost »

Bozack wrote:[...] I still think this is kind of weird - that the exp expression is not defined anywhere, and I hence have to use the Euler number... I figured this out myself as a quick fix, but to me it doesn't seem right (I think it's easier to remember the expression exp than the number 2.718). [...]
In a certain way you are right. The Postscript language hence the pstricks-add package only know Pi as a predefined value. But, according to a suggestion of the manual (p. 72ff), you can define a command that lets you forget the exact value.

Code: Select all

\def\PsEuler{2.71828182846}
The plot itself then contains this command at the appropriate place.

Code: Select all

\psplot[algebraic,linecolor=red]{-1.825}{10}{(1-(4/3)*x+(8/27)*x^2)*\PsEuler^(-(2/3)*x)}
Of course you can use this for other values as well.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

pst-plot and the exponential function

Post by Bozack »

localghost wrote:In a certain way you are right. The Postscript language hence the pstricks-add package only know Pi as a predefined value. But, according to a suggestion of the manual (p. 72ff), you can define a command that lets you forget the exact value.
I think I'll do that. Thanks for the help :)
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
Post Reply