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


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!





\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}});



Best Answer

Use pgfplots:



  axis lines=middle,
  legend pos=north west
\addplot+[mark=none,samples=200,unbounded coords=jump] {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)$};


enter image description here