3

I am trying to plot the graphs using PSTricks. I am using Miktex+Texmaker with the configurations-LeTeX+dvips+ps2pdf+ View PDF. have the following latex commands/codes:

\documentclass[11pt]{article} 
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
%\usepackage{pst-plot}
%\usepackage{pst-math}
%\usepackage{auto-pst-pdf}
\begin{document}
    \begin{figure}[h]
  \centering
  \scalebox{1.1}{
    \psset{unit=2.5cm} % Adjust the unit size as needed
    \begin{pspicture}(-3,-3)(3,3)
      \psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
      \psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
      \psplot{0}{5}{sqrt(x)}
      \psplot[linecolor=red]{-5}{5}{ATAN(x)}
    \end{pspicture}
  }
  \caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}

When I compile, the picture doesn't appear though there is no errors appearing. Please help me troubleshoot.

2
  • ps2pdf shows a postscript error Error: /typecheck in --mul-- Operand stack: 0.0 (x) 71.1319 meaning you are trying to multiply 0 bythe string x Jan 31 at 14:33
  • \psplot requires a function in PostScript syntax. Look into the manual for more information. You need to replace sqrt(x) by x sqrt for example. Jan 31 at 14:36

4 Answers 4

3

You may find it easier to use pgfplots (tikz pased) rather than pstricks unless you are happy to write the functions in postscript. x sqrt for example, arctan perhaps as below (see comments for help given on atan) although that isn't quite the form I expected.

enter image description here

\documentclass[11pt]{article} 
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
%\usepackage{pst-plot}
%\usepackage{pst-math}
%\usepackage{auto-pst-pdf}
\begin{document}
    \begin{figure}[h]
  \centering
  \scalebox{1.1}{
    \psset{unit=2.5cm} % Adjust the unit size as needed
    \begin{pspicture}(-3,-3)(3,3)
      \psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
      \psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
      \psplot{0}{5}{x sqrt}
      \psplot[linecolor=red]{0}{5}{x 1 atan 3.14159 mul 180 div}
      \psplot[linecolor=red]{-5}{0}{x -1 atan 3.14159 mul -180 div 3.14159 add}
    \end{pspicture}
  }
  \caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}
2
  • Well, \psplot[linecolor=red]{0}{5}{x 1 atan 3.14159 mul 180 div} \psplot[linecolor=red]{-5}{0}{x -1 atan 3.14159 mul -180 div 3.14159 add} would output the expected plot (you need to convert degrees to radians). (But I don't quite get, why you need to add pi to the negative part.) Jan 31 at 14:54
  • 1
    @JasperHabicht thanks, updated Jan 31 at 15:05
5

The option algebraic can be used to write normal expression. The option plotpoint can be used for better precision.

ATAN is the name of the function in radian

\documentclass[11pt]{article} 
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
\begin{document}
    \begin{figure}[ht]
  \centering
  \scalebox{1.1}{
    \psset{unit=2.5cm} % Adjust the unit size as needed
    \begin{pspicture}(-3,-3)(3,3)
      \psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
      \psaxes[showorigin=false]{->}(0,0)(-3,-3)(3,3) %showorigin=false to not dispaly "0" on axes 
            \psplot[algebraic,plotpoints=200]{0}{3}{sqrt(x)} %algebraic for classical expression and plotpoints=200 for more précisions
            \psplot[algebraic,plotpoints=200]{-3}{3}{ATAN(x)}
    \end{pspicture}
  }
  \caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}

enter image description here

For information it also works with lualatex

1
  • My favourite answer, +1
    – AlexG
    Jan 31 at 16:41
3

pst-algparser.pro defines function atg which outputs the angle in radians. Also it defines AlgParser that allows for algebraic (infix) notation as input. Input is a string , (...<infix input>...), and output is an array with PostScript commands that needs to be made executable (cvx) and finally executed exec:

\psplot[linecolor=red]{-5}{5}{(atg(x)) AlgParser cvx exec}

The PostScript built-in atan is difficult to be used (see David's answer) as it wants two arguments as input, a fraction consisting of the tangens value itself and a divisor, and it returns an angle in degrees. The fraction input allows for infinity as input:

1 0 atan => 90

To use the PostScript atan in infix notation, the following plot command would produce the expected graph:

\psplot[linecolor=red]{-5}{5}{(DegtoRad(-atan(x,-1))+Pi) AlgParser cvx exec}  

With atg:

\documentclass[11pt]{article} 
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
%\usepackage{pst-plot}
%\usepackage{pst-math}
%\usepackage{auto-pst-pdf}
\begin{document}
    \begin{figure}[h]
  \centering
  \scalebox{1.1}{
    \psset{unit=2.5cm} % Adjust the unit size as needed
    \begin{pspicture}(-3,-3)(3,3)
      \psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
      \psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
      \psplot{0}{5}{(sqrt(x)) AlgParser cvx exec}
      \psplot[linecolor=red]{-5}{5}{(atg(x)) AlgParser cvx exec}
    \end{pspicture}
  }
  \caption{The graph $G_1$}\label{Fig-2}
\end{figure}
\end{document}

enter image description here

1

Run with lualatex:

\DocumentMetadata{}
\documentclass[11pt]{article} 
\usepackage{graphicx}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{pst-all}
\begin{document}

\begin{figure}[!htb]
\centering
\psset{unit=1.5cm} % Adjust the unit size as needed
\begin{pspicture}(-3,-3)(3,3)
    \psgrid[griddots=10,gridlabels=0pt, subgriddiv=0, gridcolor=black!20]
    \psaxes{->}(0,0)(-3,-3)(3,3) % Corrected line
    \psplot[algebraic,linewidth=1.5pt]{0}{3}{sqrt(x)}
    \psplot[algebraic,linecolor=red,linewidth=1.5pt]{-3}{3}{ATAN(x)}
\end{pspicture}
\caption{The graph $G_1$}\label{Fig-2}
\end{figure}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .