I'd like to plot the function 1/2*x(x+1) in for integer values ranging from 3 to 20 and in particular I'd like the function to be plotted in those points. I have managed to create the following graph so far which obviously is not what I want
this is the code I have written:
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
xlabel={Numero di elementi},
ylabel={Numero di coppie},
xmin=3, xmax=20,
ymin=0, ymax=55,
xtick={1,...,20}
]
\addplot {0.5*x*(x-1)};
\end{axis}
\end{tikzpicture}
\end{figure}
So what is that I am doing wrong?
Best Answer
You can adjust the calculation/plotting range with the
domain
keyword. If you want the evaluated points only for integer values of x use thesamples
keyword to select the appropriate number ofsamples
within thedomain
range: