5
$\begingroup$

While working on this problem I decided to check some of my work with Mathematica:

ln[4]:= Series[u[x + h], {h, 0, 4}]

$u(x)+h u'(x)+\frac{1}{2} h^2 u''(x)+\frac{1}{6} h^3 u^{(3)}(x)+\frac{1}{24} h^4 u^{(4)}(x)+O\left(h^5\right)$

ln[5]:= Series[u[x - h], {h, 0, 4}]

$u(x)-h u'(x)+\frac{1}{2} h^2 u''(x)-\frac{1}{6} h^3 u^{(3)}(x)+\frac{1}{24} h^4 u^{(4)}(x)+O\left(h^5\right)$

(%4 + %5 - 2*u[x])/h^2

$u''(x)+\frac{1}{12} h^2 u^{(4)}(x)+O\left(h^3\right)$

As you can see, the error term in the result is $\operatorname{O}(h^3)$; however, all the odd terms should cancel and we could have $\operatorname{O}(h^4)$. How can I get Mathematica to recognize this cancellation and return the minimum error term? The order is correct if I add another term to each series, but I'd prefer a solution not requiring that.

$\endgroup$
2
  • $\begingroup$ Please post code, not images. For notes on how to do this, if unclear, see mathematica.stackexchange.com/help/formatting $\endgroup$
    – b3m2a1
    Commented Jan 7, 2018 at 20:34
  • 1
    $\begingroup$ Of course; done. $\endgroup$
    – user50010
    Commented Jan 7, 2018 at 20:43

1 Answer 1

9
$\begingroup$

You could just apply Series to the expression of interest:

Series[(u[x+h] + u[x-h] - 2 u[x])/h^2, {h, 0, 3}] //TeXForm

$u''(x)+\frac{1}{12} h^2 u^{(4)}(x)+O\left(h^4\right)$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.