# Getting the graph of a square root function using TikZ

I want the graph of the square root function to increase "slower" - maybe half the "speed."

\documentclass{amsart}
\usepackage{mathtools,systeme,array}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

If $f(x) = \sqrt{x}$ and $g(x) = \sqrt{8 - 4x}$, express $g$ in terms of $f$. Sketch both functions.
\vskip0.2in

\noindent {{\textbf{Solution}}
\begin{equation*}
g(x) =  \sqrt{8 - 4x}
=  \sqrt{4(2 - x)}
=  2\sqrt{2 - x}
= 2 f(2 - x) .
\end{equation*}
(The graph of $f(2 - x)$ is the reflection of the graph of $f(x - 2)$ across the vertical line $x = 2$.) \rule{1.5ex}{1.5ex}
\vskip0.2in

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=3in,grid=both,grid style={line width=.1pt, draw=gray!10},clip=false,
axis lines=middle,
xmin=-25,xmax=25,
ymin=-1,ymax=10.5,
restrict y to domain=-1:10.5,
xtick={-25,-20,...,30},
xticklabels={, , , , , , , , , ,},
ytick={-1,0,...,10},
yticklabels={, , , , , , , , , ,},
extra x ticks={2},
extra x tick style={xticklabel style={font=\tiny,fill=white, circle, inner sep=1.5pt}},
extra x tick labels={2},
axis line style={latex-latex},
axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
xlabel=$x$,
ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[samples=501,domain=0:25] {sqrt(x)} node[anchor=south east,pos=0.75,font=\footnotesize]{$y=f(x)$};

\addplot[samples=501, line width=0.1pt, dashed, domain=2:27, blue] {sqrt(x - 2)} node[anchor=north west,pos=0.75,font=\footnotesize]{$y=f(x-2)$};

\addplot[samples=501, line width=0.1pt, loosely dashed, domain=-23:2, green] {sqrt(2 - x)} node[anchor=north east,pos=0,font=\footnotesize]{$y=f(2 - x)$};

\addplot[samples=501, domain=-23:2, green] {2 * sqrt(2 - x)} node[anchor=north east,pos=0,font=\footnotesize]{$y=g(x)$};

\end{axis}
\end{tikzpicture}

\end{document}

• Well, you could either change the function or change the range. Jun 13, 2015 at 0:52
• @Sean Allred Would I change restrict y to domain=-1:10.5, to something like restrict y to domain=-1:50,? Will that change the y-axis? Jun 13, 2015 at 0:56
• Yeah, that will definitely change the y axis. Jun 13, 2015 at 0:59
• @Sean Allred There is an option for the axis environment that specifies the ratio of the lengths of a unit along the x-axis to a unit along the y-axis. I thought it was unit vector. I did not find it in the pgfplots manual, though. Do you know what I am referring to? Jun 14, 2015 at 19:08
• @user74973 unit vector ratio? Jun 20, 2015 at 6:46

\documentclass{amsart}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\noindent {\textbf{40.) }}If $f(x) = \sqrt{x}$ and $g(x) = \sqrt{8 - 4x}$, express $g$ in terms of $f$. Sketch both functions.
\vskip0.2in

\noindent {{\textbf{Solution}}
\begin{equation*}
g(x) =  \sqrt{8 - 4x}
=  \sqrt{4(2 - x)}
=  2\sqrt{2 - x}
= 2 f(2 - x) .
\end{equation*}
(The graph of $f(2 - x)$ is the reflection of the graph of $f(x - 2)$ across the vertical line $x = 2$.) \rule{1.5ex}{1.5ex}
\vskip0.2in

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=3in,grid=both,grid style={line width=.1pt, draw=gray!10},clip=false,
x=0.15cm, y=0.2cm,
axis lines=middle,
xmin=-28,xmax=28,
ymin=-2.5,ymax=10,
restrict y to domain=-2.5:10,
xtick={-25,-20,...,30},
xticklabels={, , , , , , , , , ,},
ytick={-2,-1,...,10},
yticklabels={, , , , , , , , , ,},
extra x ticks={2},
extra x tick style={xticklabel style={font=\tiny,fill=white, circle, inner sep=1.5pt}},
extra x tick labels={2},
axis line style={latex-latex},
axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
xlabel=$x$,
ylabel=$y$,
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[samples=501,domain=0:25] {sqrt(x)} node[anchor=south east,pos=0.75,font=\footnotesize]{$y=f(x)$};

\addplot[samples=501, line width=0.1pt, dashed, domain=2:27, blue] {sqrt(x - 2)} node[anchor=north west,pos=0.75,font=\footnotesize]{$y=f(x-2)$};

\addplot[samples=501, line width=0.1pt, loosely dashed, domain=-23:2, green] {sqrt(2 - x)} node[anchor=north east,pos=0,font=\footnotesize]{$y=f(2 - x)$};

\addplot[samples=501, domain=-23:2, green] {2 * sqrt(2 - x)} node[anchor=north east,pos=0,font=\footnotesize]{$y=g(x)$};

\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}

• I added x=0.15cm, y=0.2cm, to the axis environment. Jun 13, 2015 at 13:21