TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've seen in TikZ and pgf Manual for version 1.18 a code for graphing some functions but it does not provide an example for a rational function.

Can someone help me graph $x+\frac{1}{x}$?

share|improve this question
Did you look at Plot reciprocal function with tkiz – Ignasi Mar 7 '12 at 23:06
up vote 3 down vote accepted

Here is a quick adaptation from example from p. 225 (section 19.5) of pgfmanual (for version 2.10). Notice that due to a singularity at zero I gave the formula twice; I do not know whether this can be avoided. (Well, it can, by giving the domain and the number of samples so that no sample is taken at zero, but this would be far from elegant!)




  \draw[very thin,color=gray] (-3.1,-4.1) grid (3.9,3.9);
  \draw[->] (-3.2,0) -- (4.2,0) node[right] {$x$};
  \draw[->] (0,-4.2) -- (0,4.2) node[above] {$y$};
  \draw[color=orange,domain=-3:-0.3] plot (\x,{\x+1/\x});
  \draw[color=orange,domain=0.3:3] plot (\x,{\x+1/\x}) node[right] {$y = x+\frac{1}{x}$};

share|improve this answer
This is it. Thank you. – jgg Mar 7 '12 at 14:19

Same as mbork's answer but with pgfplots, just for academic purposes.




    axis lines=middle,
    restrict y to domain=-4:4,
    %unbounded coords=jump,
  \addplot[color=orange,domain=-3:3,samples=100] {x+1/x} node[right] {$y = x+\frac{1}{x}$};


enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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