I find in pst-plot.pdf, pst-func.pdf document but there is no its tutorial. So I hope anyone help me to draw the plot of it.(its code :-)) ). Thanks.

Example: y=(x-2)/(2x+1)

enter image description here

Can anyone draw it by Pstricks environment?

  • 2
    Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Note this is a Q&A site, not a please do this for me service. What do you have so far. – albert Nov 17 at 14:41
  • Sorry, i don't know its code so i hope anyone know about it to help me. – chishimotoji Nov 17 at 14:47
  • Vietnamese TikZ tutorial: Link – JouleV Nov 17 at 15:01
  • There is no the plot of functions y=(ax+b)/(cx+d). :)) – chishimotoji Nov 17 at 15:07
up vote 15 down vote accepted
\documentclass{article}


\usepackage{pgfplots}



\begin{document}

\begin{center}
\begin{tikzpicture}[scale=2]
\begin{axis}[axis lines=middle]
\addplot[smooth,domain=-4:-8/11,purple,very thick] {(x-2)/(2*x+1)};
\addplot[smooth,domain=-2/7:4,purple,very thick] {(x-2)/(2*x+1)};
\draw[blue] (axis cs:-0.5,-6)--(axis cs:-0.5,6)
(axis cs:-4,0.5)--(axis cs:4,0.5);
\fill[red] (axis cs:-0.5,0.5) circle(1mm);
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

  • 1
    Thank you for your answer. – chishimotoji Nov 17 at 14:56
  • 2
    @TrongVuong If you agree with this answer, then you accept it and vote for answer. – minhthien_2016 Nov 17 at 15:58
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}

\begin{document}
\begin{pspicture}[algebraic](-6,-6)(6,6)
  \psaxes{->}(0,0)(-5.5,-5.5)(5.5,5.5)[$x$,0][$y$,90]
  \psline[linecolor=red,linewidth=0.2pt](-0.5,-5.5)(-0.5,5.5)
  \psline[linecolor=red,linewidth=0.2pt](-5.5,0.5)(5.5,0.5)
  \psplot[plotpoints=1001,linecolor=blue,linewidth=2pt,
      yMaxValue=5.25]{-5.5}{5}{(x-2)/(2*x+1)}
  \psdots[linecolor=red](-0.5,0.5)(0,0)(0,-2)(1,0)(2,0) 
\end{pspicture}
\end{document}

enter image description here

A PSTricks answer for the PSTricks question.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\def\f{(x-2)/(2*x+1)}

\begin{document}
\begin{pspicture}[algebraic](-4,-4)(6,5.5)
    \psaxes{->}(0,0)(-4,-4)(5.5,5)[$x$,0][$y$,90]
    \psline[linestyle=dashed,linecolor=red](-0.5,-4)(-0.5,5)
    \psline[linestyle=dashed,linecolor=red](-4,0.5)(5,0.5)
    \psset{linecolor=blue,linewidth=2pt}
    \psplot{-4}{-7 9 div}{\f}
    \psplot{-2 9 div}{5}{\f}
\end{pspicture}
\end{document}

enter image description here

NOTE

Increasing plotpoints sometimes is not a wise method because it will increase the size of its output (either PDF or SVG).

More flexible solution

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\def\f(#1){((#1-2)/(2*(#1)+1))}% y=f(x)
\def\g(#1){((2+#1)/(1-2*(#1)))}% y=g(x) in which g is the inverse of f.

\pstVerb{/I2P {AlgParser cvx exec} def}% infix to postfix operator

\begin{document}
\begin{pspicture}[algebraic](-4,-4)(6,6)
    \psaxes{->}(0,0)(-4,-4)(5.5,5.5)[$x$,0][$y$,90]
    \psline[linestyle=dashed,linecolor=red](-0.5,-4)(-0.5,5)
    \psline[linestyle=dashed,linecolor=red](-4,0.5)(5,0.5)
    \psset{linecolor=blue,linewidth=2pt}
    \psplot{-4}{\g(5) I2P}{\f(x)}
    \psplot{\g(-4) I2P}{5}{\f(x)}
\end{pspicture}
\end{document}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.