# PGFplots problem : not the good graph

I can't find what is going wrong in the following MWE, but the output is not at all the correct function, in this case f(x) = \frac{4x^2}{(1+x)^2}, which accepts a maximum for x = 1. Can anyone help me please ?

\usemodule[tikz]
\usemodule[pgfplots]  \pgfplotsset{compat=1.12}

\starttext
\starttikzpicture
\startaxis[
axis x line=bottom, xmin=0,xmax=5,     xlabel=$R/r$,
axis y line=left,   ymin=0,ymax=1.5,     ylabel=$P/P_{\text{max}}$,
xlabel style={at={(ticklabel* cs:1)},     anchor=north},
ylabel style={at={(ticklabel* cs:1)},     anchor=east, rotate=-90},
samples=100, ticks=none, clip=false
]
\addplot[mark=none,color=black, domain=0:5] {     4*x^2 / ((1+x)^2) };
\draw [dashed] (0,1) node [left] {$1$} --     (1,1) -- (1,0) node[below] {$1$};
\stopaxis
\stoptikzpicture

\stoptext


# EDIT

Ok, the problem is just that I should stop working at 1 am... I made a mistake in the calculus, which leads to \frac{4x}{(1+x)^2} ; from the physical meaning, I knew it had to accept a maximum for x = 1, and I searched for a calculus error that I didn't find, and I finally lost faith in pgfplots. I will wait the following day to check my calculus next time. Is there a way to tag this post as non-relevant ?

• leading terms has 4/1 for the x^2 so I don't see the problem. Why do you think it is wrong? – percusse Sep 8 '16 at 22:16

Everything here seems fine, the f(x) you give will increase from f(0)=0 and tending to a maximum of 4 as x goes to infinity

Maybe you are confusing the x=1 and x=-1 cases, f(-1) is indeed infinity

Playing around with ConTeXt I seem to get the same plot as I do with Mathematica above, with f tending to 4 for large |x| and diverging at x=-1.

\usemodule[tikz]
\usemodule[pgfplots]  \pgfplotsset{compat=1.12}

\starttext
\starttikzpicture
\startaxis[
axis x line=bottom, xmin=-20,xmax=20,     xlabel=$R/r$,
axis y line=middle,   ymin=0,ymax=40,     ylabel=$P/P_{\text{max}}$,
xlabel style={at={(ticklabel* cs:1)},     anchor=north},
ylabel style={at={(ticklabel* cs:1)},     anchor=east, rotate=-90},
samples=100, ticks=none, clip=false
]
\addplot[mark=none,color=black, domain=-0.75:20] {     4*x^2 / ((1+x)^2) };
\addplot[mark=none,color=black, domain=-20:-1.5] {     4*x^2 / ((1+x)^2) };
\draw [dashed] (-1,50) -- (-1,0) node[below] {$-1$};
\draw [dashed] (-20,4) -- (20,4) node[midway, above left] {$4$};
\stopaxis
\stoptikzpicture

\stoptext