Consider the series expansion of the function \(f(x) = \exp(x)\), around \(x = x_0 = 0\), up to, say, the the 4th order term.
>>> from sympy import *
>>> x = symbols('x')
>>> series(exp(x), x, 0, 4)
1 + x + x**2/2 + x**3/6 + O(x**4)
You get what you expect.
Now consider a similar expansion centered around \(x = x_0 = 1\).
>>> series(exp(x),x, 1, 4)
E + E*x + E*x**2/2 + E*x**3/6 + O(x**4)
Clearly, this is off.
The correct expansion may be obtained by substituting \(x\) with \(x-x_0\),
>>> (series(exp(x),x, 1, 4).removeO()).subs(x,x-1)
E*(x - 1)**3/6 + E*(x - 1)**2/2 + E*(x - 1) + E
>>> from sympy import *
>>> x = symbols('x')
>>> series(exp(x), x, 0, 4)
1 + x + x**2/2 + x**3/6 + O(x**4)
Now consider a similar expansion centered around \(x = x_0 = 1\).
>>> series(exp(x),x, 1, 4)
E + E*x + E*x**2/2 + E*x**3/6 + O(x**4)
Clearly, this is off.
The correct expansion may be obtained by substituting \(x\) with \(x-x_0\),
>>> (series(exp(x),x, 1, 4).removeO()).subs(x,x-1)
E*(x - 1)**3/6 + E*(x - 1)**2/2 + E*(x - 1) + E
No comments:
Post a Comment