Error from central difference seems large












1












$begingroup$


for a function $f(x)=e^{2x}-cos(2x)$,



at grid points $x in {-0.3,-0.2,-0.1,0}$



I perform a central difference for the derivative at $x=-0.2$



$$frac{df}{dx}=frac{f(-0.1)-f(-0.3)}{2*(-0.1--0.3)}=0.28795$$
The derivative of this function (per mathematica) is $0.561803$
So the error is $$Abs[0.561803-0.28795]=0.273853$$



I have a formula for the upper bound of the error, and that formula is $$frac{M^*Delta x^2}{3!}=frac{8*(-0.1--0.3)}{6}=0.0533333\text{Where }M^*=text{Max}(f''(x)|xin[-0.3,0])=f(0)=8$$



The issue is the error, $0.27$, is greater than the supposid error bound, $0.05$. When I graph this function with its central difference though, it looks correct.



Graph of f(x) and finite/central differences



Any idea why my derivatives are higher than the upper bound? The error does seem pretty high.










share|cite|improve this question











$endgroup$

















    1












    $begingroup$


    for a function $f(x)=e^{2x}-cos(2x)$,



    at grid points $x in {-0.3,-0.2,-0.1,0}$



    I perform a central difference for the derivative at $x=-0.2$



    $$frac{df}{dx}=frac{f(-0.1)-f(-0.3)}{2*(-0.1--0.3)}=0.28795$$
    The derivative of this function (per mathematica) is $0.561803$
    So the error is $$Abs[0.561803-0.28795]=0.273853$$



    I have a formula for the upper bound of the error, and that formula is $$frac{M^*Delta x^2}{3!}=frac{8*(-0.1--0.3)}{6}=0.0533333\text{Where }M^*=text{Max}(f''(x)|xin[-0.3,0])=f(0)=8$$



    The issue is the error, $0.27$, is greater than the supposid error bound, $0.05$. When I graph this function with its central difference though, it looks correct.



    Graph of f(x) and finite/central differences



    Any idea why my derivatives are higher than the upper bound? The error does seem pretty high.










    share|cite|improve this question











    $endgroup$















      1












      1








      1


      1



      $begingroup$


      for a function $f(x)=e^{2x}-cos(2x)$,



      at grid points $x in {-0.3,-0.2,-0.1,0}$



      I perform a central difference for the derivative at $x=-0.2$



      $$frac{df}{dx}=frac{f(-0.1)-f(-0.3)}{2*(-0.1--0.3)}=0.28795$$
      The derivative of this function (per mathematica) is $0.561803$
      So the error is $$Abs[0.561803-0.28795]=0.273853$$



      I have a formula for the upper bound of the error, and that formula is $$frac{M^*Delta x^2}{3!}=frac{8*(-0.1--0.3)}{6}=0.0533333\text{Where }M^*=text{Max}(f''(x)|xin[-0.3,0])=f(0)=8$$



      The issue is the error, $0.27$, is greater than the supposid error bound, $0.05$. When I graph this function with its central difference though, it looks correct.



      Graph of f(x) and finite/central differences



      Any idea why my derivatives are higher than the upper bound? The error does seem pretty high.










      share|cite|improve this question











      $endgroup$




      for a function $f(x)=e^{2x}-cos(2x)$,



      at grid points $x in {-0.3,-0.2,-0.1,0}$



      I perform a central difference for the derivative at $x=-0.2$



      $$frac{df}{dx}=frac{f(-0.1)-f(-0.3)}{2*(-0.1--0.3)}=0.28795$$
      The derivative of this function (per mathematica) is $0.561803$
      So the error is $$Abs[0.561803-0.28795]=0.273853$$



      I have a formula for the upper bound of the error, and that formula is $$frac{M^*Delta x^2}{3!}=frac{8*(-0.1--0.3)}{6}=0.0533333\text{Where }M^*=text{Max}(f''(x)|xin[-0.3,0])=f(0)=8$$



      The issue is the error, $0.27$, is greater than the supposid error bound, $0.05$. When I graph this function with its central difference though, it looks correct.



      Graph of f(x) and finite/central differences



      Any idea why my derivatives are higher than the upper bound? The error does seem pretty high.







      finite-differences






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Dec 1 '18 at 0:48









      Key Flex

      8,18261233




      8,18261233










      asked Nov 30 '18 at 22:31









      FrankFrank

      16210




      16210






















          1 Answer
          1






          active

          oldest

          votes


















          1












          $begingroup$

          The problem lies in your definition of $Delta x$, remember that



          $$
          f'_{FD}(x) approx frac{f(x + Delta x) - f(x - Delta x)}{2Delta x}
          $$



          Taking $x = -0.2$ and $Delta x = 0.1$ we get



          $$
          f'_{FD}(-0.2) approx frac{f(-0.1) - f(-0.3)}{2 cdot 0.1} = 0.575941 tag{1}
          $$



          So the actual error is



          $$
          epsilon = |f'_{FD}(-0.2) - f'(-0.2)|= 0.0141374 tag{2}
          $$



          Now, the prediction for the error is



          $$
          epsilon_{max} = frac{|f^{(3)}(c)|Delta^2 x}{6} stackrel{c=-0.3}{=} 0.0148461 tag{3}
          $$



          You can indeed see that



          $$
          epsilon < epsilon_max
          $$






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Thanks so much! But is the formula for the error bound really supposed to be the third derivative of $f$ or the second? I got the formula from someone else's notes! I couldn't find it with a google search hahaha.
            $endgroup$
            – Frank
            Dec 1 '18 at 0:04










          • $begingroup$
            @Frank It is the third derivative
            $endgroup$
            – caverac
            Dec 1 '18 at 0:40











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "69"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          },
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3020732%2ferror-from-central-difference-seems-large%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









          1












          $begingroup$

          The problem lies in your definition of $Delta x$, remember that



          $$
          f'_{FD}(x) approx frac{f(x + Delta x) - f(x - Delta x)}{2Delta x}
          $$



          Taking $x = -0.2$ and $Delta x = 0.1$ we get



          $$
          f'_{FD}(-0.2) approx frac{f(-0.1) - f(-0.3)}{2 cdot 0.1} = 0.575941 tag{1}
          $$



          So the actual error is



          $$
          epsilon = |f'_{FD}(-0.2) - f'(-0.2)|= 0.0141374 tag{2}
          $$



          Now, the prediction for the error is



          $$
          epsilon_{max} = frac{|f^{(3)}(c)|Delta^2 x}{6} stackrel{c=-0.3}{=} 0.0148461 tag{3}
          $$



          You can indeed see that



          $$
          epsilon < epsilon_max
          $$






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Thanks so much! But is the formula for the error bound really supposed to be the third derivative of $f$ or the second? I got the formula from someone else's notes! I couldn't find it with a google search hahaha.
            $endgroup$
            – Frank
            Dec 1 '18 at 0:04










          • $begingroup$
            @Frank It is the third derivative
            $endgroup$
            – caverac
            Dec 1 '18 at 0:40
















          1












          $begingroup$

          The problem lies in your definition of $Delta x$, remember that



          $$
          f'_{FD}(x) approx frac{f(x + Delta x) - f(x - Delta x)}{2Delta x}
          $$



          Taking $x = -0.2$ and $Delta x = 0.1$ we get



          $$
          f'_{FD}(-0.2) approx frac{f(-0.1) - f(-0.3)}{2 cdot 0.1} = 0.575941 tag{1}
          $$



          So the actual error is



          $$
          epsilon = |f'_{FD}(-0.2) - f'(-0.2)|= 0.0141374 tag{2}
          $$



          Now, the prediction for the error is



          $$
          epsilon_{max} = frac{|f^{(3)}(c)|Delta^2 x}{6} stackrel{c=-0.3}{=} 0.0148461 tag{3}
          $$



          You can indeed see that



          $$
          epsilon < epsilon_max
          $$






          share|cite|improve this answer









          $endgroup$













          • $begingroup$
            Thanks so much! But is the formula for the error bound really supposed to be the third derivative of $f$ or the second? I got the formula from someone else's notes! I couldn't find it with a google search hahaha.
            $endgroup$
            – Frank
            Dec 1 '18 at 0:04










          • $begingroup$
            @Frank It is the third derivative
            $endgroup$
            – caverac
            Dec 1 '18 at 0:40














          1












          1








          1





          $begingroup$

          The problem lies in your definition of $Delta x$, remember that



          $$
          f'_{FD}(x) approx frac{f(x + Delta x) - f(x - Delta x)}{2Delta x}
          $$



          Taking $x = -0.2$ and $Delta x = 0.1$ we get



          $$
          f'_{FD}(-0.2) approx frac{f(-0.1) - f(-0.3)}{2 cdot 0.1} = 0.575941 tag{1}
          $$



          So the actual error is



          $$
          epsilon = |f'_{FD}(-0.2) - f'(-0.2)|= 0.0141374 tag{2}
          $$



          Now, the prediction for the error is



          $$
          epsilon_{max} = frac{|f^{(3)}(c)|Delta^2 x}{6} stackrel{c=-0.3}{=} 0.0148461 tag{3}
          $$



          You can indeed see that



          $$
          epsilon < epsilon_max
          $$






          share|cite|improve this answer









          $endgroup$



          The problem lies in your definition of $Delta x$, remember that



          $$
          f'_{FD}(x) approx frac{f(x + Delta x) - f(x - Delta x)}{2Delta x}
          $$



          Taking $x = -0.2$ and $Delta x = 0.1$ we get



          $$
          f'_{FD}(-0.2) approx frac{f(-0.1) - f(-0.3)}{2 cdot 0.1} = 0.575941 tag{1}
          $$



          So the actual error is



          $$
          epsilon = |f'_{FD}(-0.2) - f'(-0.2)|= 0.0141374 tag{2}
          $$



          Now, the prediction for the error is



          $$
          epsilon_{max} = frac{|f^{(3)}(c)|Delta^2 x}{6} stackrel{c=-0.3}{=} 0.0148461 tag{3}
          $$



          You can indeed see that



          $$
          epsilon < epsilon_max
          $$







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Nov 30 '18 at 23:45









          caveraccaverac

          14.6k31130




          14.6k31130












          • $begingroup$
            Thanks so much! But is the formula for the error bound really supposed to be the third derivative of $f$ or the second? I got the formula from someone else's notes! I couldn't find it with a google search hahaha.
            $endgroup$
            – Frank
            Dec 1 '18 at 0:04










          • $begingroup$
            @Frank It is the third derivative
            $endgroup$
            – caverac
            Dec 1 '18 at 0:40


















          • $begingroup$
            Thanks so much! But is the formula for the error bound really supposed to be the third derivative of $f$ or the second? I got the formula from someone else's notes! I couldn't find it with a google search hahaha.
            $endgroup$
            – Frank
            Dec 1 '18 at 0:04










          • $begingroup$
            @Frank It is the third derivative
            $endgroup$
            – caverac
            Dec 1 '18 at 0:40
















          $begingroup$
          Thanks so much! But is the formula for the error bound really supposed to be the third derivative of $f$ or the second? I got the formula from someone else's notes! I couldn't find it with a google search hahaha.
          $endgroup$
          – Frank
          Dec 1 '18 at 0:04




          $begingroup$
          Thanks so much! But is the formula for the error bound really supposed to be the third derivative of $f$ or the second? I got the formula from someone else's notes! I couldn't find it with a google search hahaha.
          $endgroup$
          – Frank
          Dec 1 '18 at 0:04












          $begingroup$
          @Frank It is the third derivative
          $endgroup$
          – caverac
          Dec 1 '18 at 0:40




          $begingroup$
          @Frank It is the third derivative
          $endgroup$
          – caverac
          Dec 1 '18 at 0:40


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematics 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.


          Use MathJax to format equations. MathJax reference.


          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%2fmath.stackexchange.com%2fquestions%2f3020732%2ferror-from-central-difference-seems-large%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?