Plot reciprocal function with tkiz

The pgfplots package has a plot drawing function that takes the parameter restrict y to domain. It takes care of the clipping and doesn't connect the points on the left and right of the singularity.

\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

  \begin{tikzpicture}
    \begin{axis}[
        restrict y to domain=-10:10,
        samples=1000,
        minor tick num=1,
        xmin = -10, xmax = 10,
        ymin = -10, ymax = 10,
        unbounded coords=jump,
        axis x line=middle,
        axis y line=middle]

      \addplot[mark=none, domain=-10:10] {(1-x)/(x^2-1)};
    \end{axis}
  \end{tikzpicture}

\end{document}

enter image description here


With TikZ version 2 :

\documentclass{article}    
\usepackage{tikz}

\begin{document}

      \begin{tikzpicture}[scale=.5] 
        \draw[->] (-10, 0) -- (10, 0) node[right] {$x$};
        \draw[->] (0, -10) -- (0, 10) node[above] {$y$};
        \draw[color=red, domain=-10:-0.1,samples=200] plot[id=x1] function{1/x};
        \draw[color=red, domain=0.1:10,samples=200] plot[id=x2] function{1/x} node[below right = 6pt] { $f(x) =1/x$ };
    \end{tikzpicture}

\end{document}

enter image description here

Tags:

Plot

Tikz Pgf