# Plot graph near zero

I want to plot the following function with TikZ. \begin{tikzpicture}[scale=0.7,
declare function={
func(\z) =  1/(2*(abs(\z)^3)) * (
(1+abs(\z)) - 2*ln(1+abs(\z)) - 1/(1+abs(\z))
);
}
]


The problem occurs near zero, the function isn't plotted the right way.

• I edited your question a bit so that it is easier for readers to understand your question. – JouleV Apr 3 at 15:37

## 1 Answer

One way that produces some plot that is reasonably close to the "true" result is to insert the Taylor expansion of the function for smallish x. Otherwise TikZ will evaluate first the 1/x^3 piece and complain. The Taylor expansion, on the other hand shows that there is no singularity. A true computer algebra system would do the limits on its own, but TeX is not such a computer algebra system.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

\begin{tikzpicture}[scale=0.7,
declare function={
func(\z)=ifthenelse(abs(\z)>0.251, 1/(2*(abs(\z)^3)) * (
(1+abs(\z)) - 2*ln(1+abs(\z)) - 1/(1+abs(\z))),
1/6 - abs(\z)/4 + (3*abs(\z)^2)/10 - abs(\z)^3/3 + (5*abs(\z)^4)/14);
}
]
\begin{axis}

\addplot[domain=-1:1,samples=31,smooth]  {func(x)};
\end{axis}
\end{tikzpicture}

\end{document} 