Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

1 Answer 1

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!)

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  \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}$};
\end{tikzpicture}

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

Your Answer

 
discard

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.