Plotting a bump function












3















I would like to plot a bump function in a similar way as its done in Loring W. Tu's Book 'An introduction to Manifolds' (page 129, fig. 13.4), however it never quite works the way I want. Here is my MWE:



documentclass[border=10pt]{standalone} 

usepackage{pgfplots}
usepackage{tikz}
pgfplotsset{%
every x tick/.style={black, thick},
every y tick/.style={black, thick},
every tick label/.append style = {font=footnotesize},
every axis label/.append style = {font=footnotesize},
compat=1.12
}
begin{document}
begin{tikzpicture}
begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,

xtick = {-1,0,1}, ytick = { 1},
scale=0.4, restrict y to domain=-1.5:1.2,
axis x line=center, axis y line= center,
samples=40]


addplot[black, samples=100, smooth, domain=-1.2:0, thick]
plot (x, { 0 });

addplot[black, samples=100, smooth, domain=0:1, thick, label={x}]
plot (x, { exp( -1/x)/(exp (-1/x)+exp(1/(x-1))) });


addplot[black, thick, samples=100, smooth, domain=1:2]
plot (x, {1} );

end{axis}
end{tikzpicture}

end{document}


My main problem with this result is, that the "plateau" is already attained before x=1, which really doesn't look like it's right. Changing sample sizes to higher than 100 will immediately yield dimension errors. Any tips?










share|improve this question



























    3















    I would like to plot a bump function in a similar way as its done in Loring W. Tu's Book 'An introduction to Manifolds' (page 129, fig. 13.4), however it never quite works the way I want. Here is my MWE:



    documentclass[border=10pt]{standalone} 

    usepackage{pgfplots}
    usepackage{tikz}
    pgfplotsset{%
    every x tick/.style={black, thick},
    every y tick/.style={black, thick},
    every tick label/.append style = {font=footnotesize},
    every axis label/.append style = {font=footnotesize},
    compat=1.12
    }
    begin{document}
    begin{tikzpicture}
    begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,

    xtick = {-1,0,1}, ytick = { 1},
    scale=0.4, restrict y to domain=-1.5:1.2,
    axis x line=center, axis y line= center,
    samples=40]


    addplot[black, samples=100, smooth, domain=-1.2:0, thick]
    plot (x, { 0 });

    addplot[black, samples=100, smooth, domain=0:1, thick, label={x}]
    plot (x, { exp( -1/x)/(exp (-1/x)+exp(1/(x-1))) });


    addplot[black, thick, samples=100, smooth, domain=1:2]
    plot (x, {1} );

    end{axis}
    end{tikzpicture}

    end{document}


    My main problem with this result is, that the "plateau" is already attained before x=1, which really doesn't look like it's right. Changing sample sizes to higher than 100 will immediately yield dimension errors. Any tips?










    share|improve this question

























      3












      3








      3








      I would like to plot a bump function in a similar way as its done in Loring W. Tu's Book 'An introduction to Manifolds' (page 129, fig. 13.4), however it never quite works the way I want. Here is my MWE:



      documentclass[border=10pt]{standalone} 

      usepackage{pgfplots}
      usepackage{tikz}
      pgfplotsset{%
      every x tick/.style={black, thick},
      every y tick/.style={black, thick},
      every tick label/.append style = {font=footnotesize},
      every axis label/.append style = {font=footnotesize},
      compat=1.12
      }
      begin{document}
      begin{tikzpicture}
      begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,

      xtick = {-1,0,1}, ytick = { 1},
      scale=0.4, restrict y to domain=-1.5:1.2,
      axis x line=center, axis y line= center,
      samples=40]


      addplot[black, samples=100, smooth, domain=-1.2:0, thick]
      plot (x, { 0 });

      addplot[black, samples=100, smooth, domain=0:1, thick, label={x}]
      plot (x, { exp( -1/x)/(exp (-1/x)+exp(1/(x-1))) });


      addplot[black, thick, samples=100, smooth, domain=1:2]
      plot (x, {1} );

      end{axis}
      end{tikzpicture}

      end{document}


      My main problem with this result is, that the "plateau" is already attained before x=1, which really doesn't look like it's right. Changing sample sizes to higher than 100 will immediately yield dimension errors. Any tips?










      share|improve this question














      I would like to plot a bump function in a similar way as its done in Loring W. Tu's Book 'An introduction to Manifolds' (page 129, fig. 13.4), however it never quite works the way I want. Here is my MWE:



      documentclass[border=10pt]{standalone} 

      usepackage{pgfplots}
      usepackage{tikz}
      pgfplotsset{%
      every x tick/.style={black, thick},
      every y tick/.style={black, thick},
      every tick label/.append style = {font=footnotesize},
      every axis label/.append style = {font=footnotesize},
      compat=1.12
      }
      begin{document}
      begin{tikzpicture}
      begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,

      xtick = {-1,0,1}, ytick = { 1},
      scale=0.4, restrict y to domain=-1.5:1.2,
      axis x line=center, axis y line= center,
      samples=40]


      addplot[black, samples=100, smooth, domain=-1.2:0, thick]
      plot (x, { 0 });

      addplot[black, samples=100, smooth, domain=0:1, thick, label={x}]
      plot (x, { exp( -1/x)/(exp (-1/x)+exp(1/(x-1))) });


      addplot[black, thick, samples=100, smooth, domain=1:2]
      plot (x, {1} );

      end{axis}
      end{tikzpicture}

      end{document}


      My main problem with this result is, that the "plateau" is already attained before x=1, which really doesn't look like it's right. Changing sample sizes to higher than 100 will immediately yield dimension errors. Any tips?







      tikz-pgf pgfplots






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 23 at 16:04









      rhodeltarhodelta

      182




      182






















          2 Answers
          2






          active

          oldest

          votes


















          3














          Welcome to TeX.SE! I do not have that book but often people use tanh for that.



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40]


          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(5*(x-0.5)))});
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here



          Of course, you can vary the width of the step by playing with the prefactor, which is 5 above.



          documentclass[border=10pt,tikz]{standalone} 
          usepackage{pgfplots}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          foreach X in {2,2.2,...,6,5.8,5.6,...,2.2}
          {begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40,
          title={$f(x)=left[1+tanhbigl(
          pgfmathprintnumber[precision=1,fixed,zerofill]{X}(x-1/2)bigr)right]/2$}]

          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(X*(x-0.5)))});
          end{axis}
          end{tikzpicture}}
          end{document}


          enter image description here






          share|improve this answer


























          • great answer, exactly what I needed thanks a lot!

            – rhodelta
            Feb 23 at 16:23






          • 1





            @ArtificialStupidity Well, fixed it, but do you think that is important here?

            – marmot
            Feb 23 at 16:29






          • 1





            Yes. It is important for me. :-) Thank you for fixing!

            – The Inventor of God
            Feb 23 at 16:59



















          2














          The plots in proferred answers do not look like what I understand to be a bump function; rather, the plots of the derivatives of the indicated functions would be bump functions. The following directly produces a bump function plot, with support the interval $[-1,1]$:



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thin},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=1.2, ymin=-0.2, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-0.2:1.2,
          axis x line=center, axis y line= center,
          samples=40]
          addplot[black, samples=100, smooth, domain=-1.2:-1, thick]
          plot (x, { 0 });
          addplot[black, samples=100, smooth, domain=-1:1, thick, label={x}]
          plot (x, {exp(1-1/(1-x^2)});
          addplot[black, thick, samples=100, smooth, domain=1:1.2]
          plot (x, {0} );
          end{axis}
          end{tikzpicture}

          end{document}


          Bump function



          (I'm unsure how to avoid the apparent gap in the graph immediately to the right of $x=-1$.)






          share|improve this answer
























          • The gap will disappear once you plot addplot[black, samples=101, smooth, domain=-1.2:1.2, thick, label={x}] plot (x, {ifthenelse(abs(x)>1,0,exp(1-1/(1-x^2))}); instead of three plots.

            – marmot
            Feb 23 at 17:15











          • @marmot: but why does the middle of the 3-part plot code fail to fill in just to the right of -1, even if I use samples=101 for that portion? Is this just due to a rounding error?

            – murray
            Feb 24 at 22:44











          • No, the function is not defined there. LaTeX does not take limits. So you ask it to evaluate exp(1-1/(1-x^2)) at x=-1 and when LaTeX parses this, it just sees an infinity resulting from -1/(1-x^2) while it does not care whether or not the infinity means that the exponential will vanish. As a consequence, it drops this coordinate, and starts the plot at the next point. If you draw everything in one stretch, it will still drop these coordinates, but then connect two "well-behaved" points, so that there won't be a gap.

            – marmot
            Feb 24 at 22:57











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


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476350%2fplotting-a-bump-function%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Welcome to TeX.SE! I do not have that book but often people use tanh for that.



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40]


          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(5*(x-0.5)))});
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here



          Of course, you can vary the width of the step by playing with the prefactor, which is 5 above.



          documentclass[border=10pt,tikz]{standalone} 
          usepackage{pgfplots}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          foreach X in {2,2.2,...,6,5.8,5.6,...,2.2}
          {begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40,
          title={$f(x)=left[1+tanhbigl(
          pgfmathprintnumber[precision=1,fixed,zerofill]{X}(x-1/2)bigr)right]/2$}]

          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(X*(x-0.5)))});
          end{axis}
          end{tikzpicture}}
          end{document}


          enter image description here






          share|improve this answer


























          • great answer, exactly what I needed thanks a lot!

            – rhodelta
            Feb 23 at 16:23






          • 1





            @ArtificialStupidity Well, fixed it, but do you think that is important here?

            – marmot
            Feb 23 at 16:29






          • 1





            Yes. It is important for me. :-) Thank you for fixing!

            – The Inventor of God
            Feb 23 at 16:59
















          3














          Welcome to TeX.SE! I do not have that book but often people use tanh for that.



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40]


          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(5*(x-0.5)))});
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here



          Of course, you can vary the width of the step by playing with the prefactor, which is 5 above.



          documentclass[border=10pt,tikz]{standalone} 
          usepackage{pgfplots}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          foreach X in {2,2.2,...,6,5.8,5.6,...,2.2}
          {begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40,
          title={$f(x)=left[1+tanhbigl(
          pgfmathprintnumber[precision=1,fixed,zerofill]{X}(x-1/2)bigr)right]/2$}]

          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(X*(x-0.5)))});
          end{axis}
          end{tikzpicture}}
          end{document}


          enter image description here






          share|improve this answer


























          • great answer, exactly what I needed thanks a lot!

            – rhodelta
            Feb 23 at 16:23






          • 1





            @ArtificialStupidity Well, fixed it, but do you think that is important here?

            – marmot
            Feb 23 at 16:29






          • 1





            Yes. It is important for me. :-) Thank you for fixing!

            – The Inventor of God
            Feb 23 at 16:59














          3












          3








          3







          Welcome to TeX.SE! I do not have that book but often people use tanh for that.



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40]


          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(5*(x-0.5)))});
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here



          Of course, you can vary the width of the step by playing with the prefactor, which is 5 above.



          documentclass[border=10pt,tikz]{standalone} 
          usepackage{pgfplots}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          foreach X in {2,2.2,...,6,5.8,5.6,...,2.2}
          {begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40,
          title={$f(x)=left[1+tanhbigl(
          pgfmathprintnumber[precision=1,fixed,zerofill]{X}(x-1/2)bigr)right]/2$}]

          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(X*(x-0.5)))});
          end{axis}
          end{tikzpicture}}
          end{document}


          enter image description here






          share|improve this answer















          Welcome to TeX.SE! I do not have that book but often people use tanh for that.



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40]


          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(5*(x-0.5)))});
          end{axis}
          end{tikzpicture}
          end{document}


          enter image description here



          Of course, you can vary the width of the step by playing with the prefactor, which is 5 above.



          documentclass[border=10pt,tikz]{standalone} 
          usepackage{pgfplots}
          pgfplotsset{%
          every x tick/.style={black, thick},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          foreach X in {2,2.2,...,6,5.8,5.6,...,2.2}
          {begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=2, ymin=-0.7, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-1.5:1.2,
          axis x line=center, axis y line= center,
          samples=40,
          title={$f(x)=left[1+tanhbigl(
          pgfmathprintnumber[precision=1,fixed,zerofill]{X}(x-1/2)bigr)right]/2$}]

          addplot[black, samples=100, smooth, domain=-1.2:2, thick]
          plot (x, {0.5*(1+tanh(X*(x-0.5)))});
          end{axis}
          end{tikzpicture}}
          end{document}


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 23 at 16:37

























          answered Feb 23 at 16:11









          marmotmarmot

          105k4126241




          105k4126241













          • great answer, exactly what I needed thanks a lot!

            – rhodelta
            Feb 23 at 16:23






          • 1





            @ArtificialStupidity Well, fixed it, but do you think that is important here?

            – marmot
            Feb 23 at 16:29






          • 1





            Yes. It is important for me. :-) Thank you for fixing!

            – The Inventor of God
            Feb 23 at 16:59



















          • great answer, exactly what I needed thanks a lot!

            – rhodelta
            Feb 23 at 16:23






          • 1





            @ArtificialStupidity Well, fixed it, but do you think that is important here?

            – marmot
            Feb 23 at 16:29






          • 1





            Yes. It is important for me. :-) Thank you for fixing!

            – The Inventor of God
            Feb 23 at 16:59

















          great answer, exactly what I needed thanks a lot!

          – rhodelta
          Feb 23 at 16:23





          great answer, exactly what I needed thanks a lot!

          – rhodelta
          Feb 23 at 16:23




          1




          1





          @ArtificialStupidity Well, fixed it, but do you think that is important here?

          – marmot
          Feb 23 at 16:29





          @ArtificialStupidity Well, fixed it, but do you think that is important here?

          – marmot
          Feb 23 at 16:29




          1




          1





          Yes. It is important for me. :-) Thank you for fixing!

          – The Inventor of God
          Feb 23 at 16:59





          Yes. It is important for me. :-) Thank you for fixing!

          – The Inventor of God
          Feb 23 at 16:59











          2














          The plots in proferred answers do not look like what I understand to be a bump function; rather, the plots of the derivatives of the indicated functions would be bump functions. The following directly produces a bump function plot, with support the interval $[-1,1]$:



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thin},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=1.2, ymin=-0.2, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-0.2:1.2,
          axis x line=center, axis y line= center,
          samples=40]
          addplot[black, samples=100, smooth, domain=-1.2:-1, thick]
          plot (x, { 0 });
          addplot[black, samples=100, smooth, domain=-1:1, thick, label={x}]
          plot (x, {exp(1-1/(1-x^2)});
          addplot[black, thick, samples=100, smooth, domain=1:1.2]
          plot (x, {0} );
          end{axis}
          end{tikzpicture}

          end{document}


          Bump function



          (I'm unsure how to avoid the apparent gap in the graph immediately to the right of $x=-1$.)






          share|improve this answer
























          • The gap will disappear once you plot addplot[black, samples=101, smooth, domain=-1.2:1.2, thick, label={x}] plot (x, {ifthenelse(abs(x)>1,0,exp(1-1/(1-x^2))}); instead of three plots.

            – marmot
            Feb 23 at 17:15











          • @marmot: but why does the middle of the 3-part plot code fail to fill in just to the right of -1, even if I use samples=101 for that portion? Is this just due to a rounding error?

            – murray
            Feb 24 at 22:44











          • No, the function is not defined there. LaTeX does not take limits. So you ask it to evaluate exp(1-1/(1-x^2)) at x=-1 and when LaTeX parses this, it just sees an infinity resulting from -1/(1-x^2) while it does not care whether or not the infinity means that the exponential will vanish. As a consequence, it drops this coordinate, and starts the plot at the next point. If you draw everything in one stretch, it will still drop these coordinates, but then connect two "well-behaved" points, so that there won't be a gap.

            – marmot
            Feb 24 at 22:57
















          2














          The plots in proferred answers do not look like what I understand to be a bump function; rather, the plots of the derivatives of the indicated functions would be bump functions. The following directly produces a bump function plot, with support the interval $[-1,1]$:



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thin},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=1.2, ymin=-0.2, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-0.2:1.2,
          axis x line=center, axis y line= center,
          samples=40]
          addplot[black, samples=100, smooth, domain=-1.2:-1, thick]
          plot (x, { 0 });
          addplot[black, samples=100, smooth, domain=-1:1, thick, label={x}]
          plot (x, {exp(1-1/(1-x^2)});
          addplot[black, thick, samples=100, smooth, domain=1:1.2]
          plot (x, {0} );
          end{axis}
          end{tikzpicture}

          end{document}


          Bump function



          (I'm unsure how to avoid the apparent gap in the graph immediately to the right of $x=-1$.)






          share|improve this answer
























          • The gap will disappear once you plot addplot[black, samples=101, smooth, domain=-1.2:1.2, thick, label={x}] plot (x, {ifthenelse(abs(x)>1,0,exp(1-1/(1-x^2))}); instead of three plots.

            – marmot
            Feb 23 at 17:15











          • @marmot: but why does the middle of the 3-part plot code fail to fill in just to the right of -1, even if I use samples=101 for that portion? Is this just due to a rounding error?

            – murray
            Feb 24 at 22:44











          • No, the function is not defined there. LaTeX does not take limits. So you ask it to evaluate exp(1-1/(1-x^2)) at x=-1 and when LaTeX parses this, it just sees an infinity resulting from -1/(1-x^2) while it does not care whether or not the infinity means that the exponential will vanish. As a consequence, it drops this coordinate, and starts the plot at the next point. If you draw everything in one stretch, it will still drop these coordinates, but then connect two "well-behaved" points, so that there won't be a gap.

            – marmot
            Feb 24 at 22:57














          2












          2








          2







          The plots in proferred answers do not look like what I understand to be a bump function; rather, the plots of the derivatives of the indicated functions would be bump functions. The following directly produces a bump function plot, with support the interval $[-1,1]$:



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thin},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=1.2, ymin=-0.2, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-0.2:1.2,
          axis x line=center, axis y line= center,
          samples=40]
          addplot[black, samples=100, smooth, domain=-1.2:-1, thick]
          plot (x, { 0 });
          addplot[black, samples=100, smooth, domain=-1:1, thick, label={x}]
          plot (x, {exp(1-1/(1-x^2)});
          addplot[black, thick, samples=100, smooth, domain=1:1.2]
          plot (x, {0} );
          end{axis}
          end{tikzpicture}

          end{document}


          Bump function



          (I'm unsure how to avoid the apparent gap in the graph immediately to the right of $x=-1$.)






          share|improve this answer













          The plots in proferred answers do not look like what I understand to be a bump function; rather, the plots of the derivatives of the indicated functions would be bump functions. The following directly produces a bump function plot, with support the interval $[-1,1]$:



          documentclass[border=10pt]{standalone} 

          usepackage{pgfplots}
          usepackage{tikz}
          pgfplotsset{%
          every x tick/.style={black, thin},
          every y tick/.style={black, thick},
          every tick label/.append style = {font=footnotesize},
          every axis label/.append style = {font=footnotesize},
          compat=1.12
          }
          begin{document}
          begin{tikzpicture}
          begin{axis}[xmin=-1.2, xmax=1.2, ymin=-0.2, ymax=1.2,
          xtick = {-1,0,1}, ytick = { 1},
          scale=0.4, restrict y to domain=-0.2:1.2,
          axis x line=center, axis y line= center,
          samples=40]
          addplot[black, samples=100, smooth, domain=-1.2:-1, thick]
          plot (x, { 0 });
          addplot[black, samples=100, smooth, domain=-1:1, thick, label={x}]
          plot (x, {exp(1-1/(1-x^2)});
          addplot[black, thick, samples=100, smooth, domain=1:1.2]
          plot (x, {0} );
          end{axis}
          end{tikzpicture}

          end{document}


          Bump function



          (I'm unsure how to avoid the apparent gap in the graph immediately to the right of $x=-1$.)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 23 at 16:57









          murraymurray

          2,1671031




          2,1671031













          • The gap will disappear once you plot addplot[black, samples=101, smooth, domain=-1.2:1.2, thick, label={x}] plot (x, {ifthenelse(abs(x)>1,0,exp(1-1/(1-x^2))}); instead of three plots.

            – marmot
            Feb 23 at 17:15











          • @marmot: but why does the middle of the 3-part plot code fail to fill in just to the right of -1, even if I use samples=101 for that portion? Is this just due to a rounding error?

            – murray
            Feb 24 at 22:44











          • No, the function is not defined there. LaTeX does not take limits. So you ask it to evaluate exp(1-1/(1-x^2)) at x=-1 and when LaTeX parses this, it just sees an infinity resulting from -1/(1-x^2) while it does not care whether or not the infinity means that the exponential will vanish. As a consequence, it drops this coordinate, and starts the plot at the next point. If you draw everything in one stretch, it will still drop these coordinates, but then connect two "well-behaved" points, so that there won't be a gap.

            – marmot
            Feb 24 at 22:57



















          • The gap will disappear once you plot addplot[black, samples=101, smooth, domain=-1.2:1.2, thick, label={x}] plot (x, {ifthenelse(abs(x)>1,0,exp(1-1/(1-x^2))}); instead of three plots.

            – marmot
            Feb 23 at 17:15











          • @marmot: but why does the middle of the 3-part plot code fail to fill in just to the right of -1, even if I use samples=101 for that portion? Is this just due to a rounding error?

            – murray
            Feb 24 at 22:44











          • No, the function is not defined there. LaTeX does not take limits. So you ask it to evaluate exp(1-1/(1-x^2)) at x=-1 and when LaTeX parses this, it just sees an infinity resulting from -1/(1-x^2) while it does not care whether or not the infinity means that the exponential will vanish. As a consequence, it drops this coordinate, and starts the plot at the next point. If you draw everything in one stretch, it will still drop these coordinates, but then connect two "well-behaved" points, so that there won't be a gap.

            – marmot
            Feb 24 at 22:57

















          The gap will disappear once you plot addplot[black, samples=101, smooth, domain=-1.2:1.2, thick, label={x}] plot (x, {ifthenelse(abs(x)>1,0,exp(1-1/(1-x^2))}); instead of three plots.

          – marmot
          Feb 23 at 17:15





          The gap will disappear once you plot addplot[black, samples=101, smooth, domain=-1.2:1.2, thick, label={x}] plot (x, {ifthenelse(abs(x)>1,0,exp(1-1/(1-x^2))}); instead of three plots.

          – marmot
          Feb 23 at 17:15













          @marmot: but why does the middle of the 3-part plot code fail to fill in just to the right of -1, even if I use samples=101 for that portion? Is this just due to a rounding error?

          – murray
          Feb 24 at 22:44





          @marmot: but why does the middle of the 3-part plot code fail to fill in just to the right of -1, even if I use samples=101 for that portion? Is this just due to a rounding error?

          – murray
          Feb 24 at 22:44













          No, the function is not defined there. LaTeX does not take limits. So you ask it to evaluate exp(1-1/(1-x^2)) at x=-1 and when LaTeX parses this, it just sees an infinity resulting from -1/(1-x^2) while it does not care whether or not the infinity means that the exponential will vanish. As a consequence, it drops this coordinate, and starts the plot at the next point. If you draw everything in one stretch, it will still drop these coordinates, but then connect two "well-behaved" points, so that there won't be a gap.

          – marmot
          Feb 24 at 22:57





          No, the function is not defined there. LaTeX does not take limits. So you ask it to evaluate exp(1-1/(1-x^2)) at x=-1 and when LaTeX parses this, it just sees an infinity resulting from -1/(1-x^2) while it does not care whether or not the infinity means that the exponential will vanish. As a consequence, it drops this coordinate, and starts the plot at the next point. If you draw everything in one stretch, it will still drop these coordinates, but then connect two "well-behaved" points, so that there won't be a gap.

          – marmot
          Feb 24 at 22:57


















          draft saved

          draft discarded




















































          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%2f476350%2fplotting-a-bump-function%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

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?