# Tikz isn't plotting the right function

Im trying to plot a probability function in tikz, but the line plotted isn't even close to how the function should look. Im new to using latex and I have no idea why this isnt working, unless tikz just cant handle this function. Here is my code:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[
declare function={Probability(\n,\k) = 1-((\n!)/((\n^(\k))*((\n-
\k)!)));}
]

\begin{axis}[
no markers, domain=0:15, samples=2500,
axis lines=left, xlabel=$k$, ylabel=$y$,
every axis y label/.style={at=(current axis.above origin),anchor=east},
every axis x label/.style={at=(current axis.right of origin),anchor=north},
height=10cm, width=15cm,
xtick={0,2,4,6,8,10,12,14},
ytick={0.1,0.2,0.3,0.4,0.5,.6,.7,.8,.9,1},
enlargelimits=false, clip=false, axis on top,
grid = major,
xmax=15
]

\end{axis}
\end{tikzpicture}
\end{document}


This is what the function should look like, And this is what tikz is plotting

I would appreciate it if someone could point me in the right direction. Thanks

answer addresses only pgfplots aspect. for drawing (vertical) lines you need to add option ycomb:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[
declare function={p(\n,\k) = 1-((\n!)/((\n^(\k))*((\n-\k)!)));}
]
\begin{axis}[axis lines=middle,
xlabel=$k$, ylabel=$y$,
ylabel style={anchor=south},
xlabel style={anchor=west},
ymax=1.2, xmax=15.5,
domain=0:15, samples=150,
no markers
]
\end{axis}
\end{tikzpicture}

\end{document}


addendum: image with correct settings of your probability function (variables should be integers) is:

\begin{tikzpicture}[
declare function={p(\n,\k) = 1-((\n!)/((\n^(\k))*((\n-\k)!)));}
]
\begin{axis}[axis lines=middle,
xlabel=$k$, ylabel=$y$,
ylabel style={anchor=south},
xlabel style={anchor=west},
ymax=1.1, xmax=32,      % <-------
domain=0:30, samples=31,% <-------
%            no markers
]

• regarding pgfplots you not use ycomb macro, regarding function: you use far to mach samples and selected function parameters lead to"strange" image. i didn't check definition of your function, however negative probabilities is unlike. – Zarko Nov 18 '17 at 0:49
• hm, that is math problem ... one way can be increase function domain (for example domain=0:120) and select sample number equal to domain (samples=120) – Zarko Nov 18 '17 at 0:57