3

The following code instructs TikZ to draw the graph described by the equation y=\frac{\sqrt{x^{2}-25}}{\sqrt{x-5}}. (This graph looks like y=\sqrt{x+5}.) I specifically want two numbers, -5 and 5, on the x-axis to be labeled. Without specifying scaling, the y-axis is magnified much more than the x-axis and the graph does not resemble y=\sqrt{x+5}.To get the same scaling for both axes while keeping the width and height unchanged, I used the optional command set axis equal. Since the function is a positive function, the part of the Cartesian plane that is drawn almost includes nothing below the x-axis. So, the labels for -5 and 5 are only partially set. (You have to look carefully to see any part of these two numbers.) How do I artificially extend the y-axis downwards a bit ... at least so that the labels -5 and 5 are drawn on the graph?

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}

%http://pgfplots.sourceforge.net/pgfplots.pdf

\begin{document}

\hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
          xmax=26,ymax=7,
          axis lines=middle,
          restrict y to domain=-3:6.5,
          enlargelimits,
          axis line style={shorten >=-0.25cm,shorten <=-0.25cm,latex-latex},
          ticklabel style={fill=white},
          extra x ticks={-5,5},
          %extra x tick style={grid=none}
]
\pgfplotsset{ticks=none}
\addplot[domain=5:26,mark=none,samples=201] {sqrt(x + 5)} node[fill=white, below left, yshift=-3pt]{$\scriptstyle y=\frac{\sqrt{x^{2}-25}}{\sqrt{x-5}}$};
\addplot[domain=-6:5,dashed,thin,mark=none,samples=201] {sqrt(x + 5)};

\draw [densely dashed] (5,3.16227766) -- (5,0) node[below]{$5$};
\draw[fill] (-5,0) circle [radius=1.5pt] node[below]{$-5$};
\draw [fill=white] (5,3.16227766) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\hspace{\fill}


\end{document}
  • How can (x^2-25)/sqrt(x-5) become similar to sqrt(x+5)? – kiss my armpit Sep 21 '14 at 11:11
4

When you put \pgfplotsset{ticks=none} after \begin{axis}, you're switching off all tick marks, including the extra x ticks that you set in the axis options.

If you only want to place tick marks at some selected coordinates, simply set xtick={-5, 5}:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[width=4in,axis equal image,
          xmax=26,ymax=7,
          axis lines=middle,
          restrict y to domain=-3:6.5,
          enlargelimits={abs=1cm},
          axis line style={latex-latex},
          ticklabel style={fill=white},
          xtick={-5,5}
]
\addplot[domain=5:26,mark=none,samples=201] {sqrt(x + 5)} node [below left, yshift=-3pt]{$\scriptstyle{y}=\frac{x^{2} - 25}{\sqrt{x - 5}}$};
\addplot[domain=-6:5,dashed,thin,mark=none,samples=201] {sqrt(x + 5)};

\draw [densely dashed] (5,3.16227766) -- (5,0);
\draw [fill] (-5,0) circle [radius=1.5pt];
\draw [fill=white] (5,3.16227766) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\end{document}
  • Are there tick marks on the y-axis by default? In case I decide not to have the tick marks of 5 and 10 on the y-axis, what code will remove them? – user143462 Sep 18 '14 at 18:21
  • 2
    @user143462: You can switch off the tick marks for the y axis by setting ytick=\empty – Jake Sep 18 '14 at 18:24
  • How can (x^2-25)/sqrt(x-5) become similar to sqrt(x+5)? – kiss my armpit Sep 21 '14 at 11:10
  • @ohmyghost: Simple – Jake Sep 21 '14 at 16:46
  • 1
    I think you did not realize that the square root is missing in your label. It should be $\frac{\sqrt{x^2-25}}{\sqrt{x-5}}$. – kiss my armpit Sep 21 '14 at 17:53
0

Correcting the existing answers and question with PSTricks.

\documentclass[pstricks,border=15pt,12pt]{standalone}
\usepackage{pst-plot}

\def\f{sqrt(x+5)}

\begin{document}
\begin{psgraph}[Dy=5,ticks=y,labels=y]{->}(0,0)(-7,-1)(12,11){12cm}{8cm}
    \psset{algebraic,plotpoints=150,linecolor=red}
    \psplot[linestyle=dashed,arrows=*-]{-5}{5}{\f}
    \psplot[arrows=o-]{5}{12}{\f}
    \psxTick(-5){-5}
    \psxTick(5){5}
    \uput[135](*10 {\f}){$\displaystyle y=\frac{\sqrt{x^2-25}}{\sqrt{x-5}}$}    
\end{psgraph}
\end{document}

enter image description here

  • What's happening at 5? – percusse Sep 21 '14 at 19:30
  • @percusse: Nothing happens. – kiss my armpit Sep 22 '14 at 4:39
0

A PSTricks solution using the pst-plot package:

\documentclass{article}

\usepackage{pst-plot}

\newcommand*\Label[1]{
  \psline(!#1 #1 5 add sqrt)(#1,0)
  \psdot(#1,0)
  \uput[270](#1,0){$#1$}
}

\begin{document}

\psset{
  unit = 0.26,
  algebraic
}
\begin{pspicture}(-8,-3)(36.4,13.5)
% points
\def\pointA{-5 }
\def\pointB{5 }
\def\pointC{30 }
  % drawing
  \psaxes[
    Dy = 5,
    labels = y,
    ticks = y
  ]{->}(0,0)(-8,-3)(35,12)[$x$,0][$y$,90]
  \psplot{\pointB}{\pointC}{sqrt(x + 5)}
 \psset{
   linestyle = dotted
 }
  \psplot{\pointA}{\pointB}{sqrt(x + 5)}
  \Label{\pointA}
  \Label{\pointB}
  \psdot[dotstyle = Bo](!\pointB \pointB 5 add sqrt)
  \uput[90](!\pointC \pointC 5 sub sqrt 1 add){%
    $\displaystyle y = \frac{\sqrt{x^{2} - 25}}{\sqrt{x - 5}}$%
  }
\end{pspicture}

\end{document}

output

All you have to do is choose the values of \pointA (left-most x-value), \pointB (dotted and solid curves meet), and \pointC (label point and end point for solid curve). The drawing will then be adjusted accordingly.

  • How can (x^2-25)/sqrt(x-5) become similar to sqrt(x+5)? – kiss my armpit Sep 21 '14 at 11:12
  • @Ohmyghost No idea but that is what the OP says in the question. I will say that it's (x+5)\sqrt{x-5}. – Svend Tveskæg Sep 21 '14 at 11:15
  • So the label in your output should be $y=\sqrt(x^2-25)/\sqrt(x-5)$. – kiss my armpit Sep 21 '14 at 11:17
  • @Ohmyghost Ohhh! I missed the square root. Thanks for pointing it out. – Svend Tveskæg Sep 21 '14 at 11:19
  • I am making a test for a Business Calculus class. I was emphasizing functions that have restricted domains. The example that I presented in class was that the graph of the "messy looking" function y=(x^{2}-4)/(x-2) looks like the line y=x+2 except at 2. This "messy looking" function that I wanted graphed looks like a horizontal shift of the square root function except for an interval, not just a point. I thought it was an interesting variation. It also requires students to know the algebraic properties of radicals. – user143462 Sep 21 '14 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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