# TiKZ won't graph 1/sqrt(x)

Evening!

Posting a quick message here cause I have a small problem with TiKZ. I've been trying to plot the function 1/sqrt(x), and it just... won't work.

Here is the code I've been typing:

\begin{tikzpicture}[scale = 1]
\begin{axis}[
domain=0:100,
xscale=1,yscale=1,
xmin=0, xmax=100,
ymin=0, ymax= 1,
samples=10000,
axis lines=center,
]
\draw[thick, samples = 1000, blue] plot[domain=0:100] ({\x, 1/sqrt(\x)});
\end{axis}
\end{tikzpicture}

But here's what I get:

I tried with other functions, still have problems. For example, if I just plot sqrt(x), here's what I get:

At least, the shape is now right... but the values are completely off.

So if anyone should have any idea on how to correct that code, I'd be really grateful, thanks :)

• Welcome to TeX-SE! 1/sqrt(\x) has a singularity at 0 and should fall for larger \x. But the technical reason why it does not work is that you set the braces wrongly, (\x,{ 1/sqrt(\x)}) is correct but still has the singularity. – user121799 Jun 13 at 20:22
• Possibly the values are off too because you didn't specify the (correct) \pgfplotssetcompatibility (which is why it's important to provide a fully functional MWE ;). – JJM Driessen Jun 13 at 20:33

Diagram of the function 1/sqrt(x) is the following:

In your MWE you have mix of pgfplotsand plain tikz syntax. Better is stick to just one of them. For example to pgfplots:

\documentclass[border=3mm]{standalone}% <-- changed
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
\begin{axis}
ymin=0, ymax=1,
axis lines=center,
]
\end{axis}
\end{tikzpicture}
\end{document}
• Oh, ok, thanks for the answer. I tried it, it works great! :) – Arthur Jun 13 at 20:48

As mentioned in the comments above, the syntax was incorrect. Since you seem to be using pgfplots, here is the way to do it. I exclude the singularity, and in pgfplots there is no need to put a backslash before x. Also I reduced the number of samples.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[scale = 1]
\begin{axis}[domain=0:100,
xscale=1,yscale=1,
xmin=0, xmax=100,
ymin=0, ymax= 1,
samples=501,
axis lines=center,
]