I want to plot the following function with TikZ.

enter image description here

    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.
    – user156344
    Apr 3, 2019 at 15:37

1 Answer 1


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.


    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);

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


enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.