# [Tex/LaTex] Plot the square root function using Tikz

diagramstikz-pgf

I want to draw the graph the function $y=\sqrt{x}$ (and label it above the graph of the function) in an $x-y$ plane. Then I need to put a filled dot on the point $(4,0)$ (I want to label $(4,0)$ beneath the dot, and I also I need to put a filled dot on an arbitrary point on the graph of the function and label $(x,y)$ above the point. I need the graph for the following problem:\
Find the point $(x,y)$ on the graph of $y=\sqrt{x}$\ \ nearest the point $(4,0)$.\

I did the following, but for some reason I couldn't even get the graph of the square root function. Thanks!

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\draw[->] (-3,0) -- (7,0) node[right] {$x$};

\draw[->] (0,-3) -- (0,4) node[above] {$y$};

\draw[scale=0.5,domain=0:9,smooth,variable=\x,blue] plot ({\x},{\sqrt{\x}});

\end{tikzpicture}

\end{document}


\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
clip=false,
ymin=0,
xticklabels=\empty,
yticklabels=\empty,
legend pos=north west
]
\legend{$y=\sqrt{x}$}
\draw[fill] (axis cs:4,0) circle [radius=1.5pt] node[below right] {$(4,0)$};
\draw[fill] (axis cs:{4.5,sqrt(4.5)}) circle [radius=1.5pt] node[above left] {$(x,y)$}; 