Plot graph near zero












3















I want to plot the following function with TikZ.



enter image description here



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.










share|improve this question









New contributor




joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • I edited your question a bit so that it is easier for readers to understand your question.

    – JouleV
    10 hours ago
















3















I want to plot the following function with TikZ.



enter image description here



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.










share|improve this question









New contributor




joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • I edited your question a bit so that it is easier for readers to understand your question.

    – JouleV
    10 hours ago














3












3








3


1






I want to plot the following function with TikZ.



enter image description here



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.










share|improve this question









New contributor




joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I want to plot the following function with TikZ.



enter image description here



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.







tikz-pgf pgfplots plot






share|improve this question









New contributor




joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 10 hours ago









JouleV

10.3k22558




10.3k22558






New contributor




joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 11 hours ago









joejoe

161




161




New contributor




joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






joe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • I edited your question a bit so that it is easier for readers to understand your question.

    – JouleV
    10 hours ago



















  • I edited your question a bit so that it is easier for readers to understand your question.

    – JouleV
    10 hours ago

















I edited your question a bit so that it is easier for readers to understand your question.

– JouleV
10 hours ago





I edited your question a bit so that it is easier for readers to understand your question.

– JouleV
10 hours ago










1 Answer
1






active

oldest

votes


















0














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}


enter image description here






share|improve this answer


























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    joe is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483003%2fplot-graph-near-zero%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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}


    enter image description here






    share|improve this answer






























      0














      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}


      enter image description here






      share|improve this answer




























        0












        0








        0







        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}


        enter image description here






        share|improve this 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}


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 7 hours ago

























        answered 10 hours ago









        marmotmarmot

        114k5145276




        114k5145276






















            joe is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            joe is a new contributor. Be nice, and check out our Code of Conduct.













            joe is a new contributor. Be nice, and check out our Code of Conduct.












            joe is a new contributor. Be nice, and check out our Code of Conduct.
















            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483003%2fplot-graph-near-zero%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)