# Plot in TikZ: f(x) = 1/(x – 2) + 3

I am trying to plot the function f(x) = 1/(x-2) + 3 using TikZ, however I get that the domain is undefined.

What code should I type?

-

You can use pgfplots instead:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[axis lines=middle,samples=200]
\draw[red!20,dashed] (axis cs:2,-4) -- (axis cs:2,10);
\end{axis}
\end{tikzpicture}

\end{document}


\documentclass{article}
\usepackage{pgfplots}

\pgfplotsset{every tick label/.style={inner sep=0pt,font=\scriptsize}}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
samples=200,
xtick={-3,...,6},
ytick={-3,...,9}
]
\draw[red!20,dashed] (axis cs:2,-4) -- (axis cs:2,10);
\end{axis}
\end{tikzpicture}

\end{document}


-
thanks; how can I make the axis are numbered from $1$ to $8$? (not just even numbers) – user10 Nov 6 '12 at 1:06
@user10 please see my updated answer. – Gonzalo Medina Nov 6 '12 at 1:14

Whatever your problem was, split the function at x = 2.

In my answer I provide two ways: pgfplots and vanilla TikZ.

## MWE

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=-5,
ymax=5,
xmin=-10.1,
xmax=10.1,
axis on top=true,
axis x line=middle,
axis y line=middle,
]
\addplot [forget plot, samples=100, domain=-10:1.99] {1/(x-2) + 3};
\addplot [             samples=100, domain=2.01:10] {1/(x-2) + 3};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[scale=.3]
\draw plot [
samples=100,
domain=-10:1.9
] (\x,{1/(\x-2) + 3});
\draw plot [
samples=100,
domain=2.1:10
] (\x,{1/(\x-2) + 3});
\end{tikzpicture}
\end{document}


-