Taylor series / series method ... again...

17 views
Skip to first unread message

bern...@gmail.com

unread,
Apr 28, 2017, 10:40:26 AM4/28/17
to sympy
OK.. I seemed to think that the series method gets the correct result. But it does not entirely...

>>> import sympy as sy
>>> x = Symbol("x")

# Basic calling of series method is "sy.series(function, x0=..., n=...)" where x0 is the point at which the expansion is taken at, while n is the order of the *error*! (*not* the number of terms *prior* to the error term!!) Other tools I have used imply that the error is of order (n+1) when n is specified, so this is sort of confusing.

>>> sy.series(sy.sin(x),x0=0)
 x - x**3/6 + x**5/120 + O(x**6)
>>> sy.series(sy.sin(x),x0=sy.pi/2)
 1 - (x - pi/2)**2/2 + (x - pi/2)**4/24 + O((x - pi/2)**6, (x, pi/2))
>>> sy.series(sy.sin(x),x0=sy.pi)
 pi + (x - pi)**3/6 - (x - pi)**5/120 - x + O((x - pi)**6, (x, pi))

# The above seems to be ok. But what if I expand to a different number of terms than the default?

>>> sy.series(sy.sin(x),x0=sy.pi/2,n=1)
 O(x - pi/2, (x, pi/2))
# The result *should* have been 1 + O(**1)! The value for sin(pi/2) is missing.

>>> sy.series(sy.sin(x),x0=sy.pi/2,n=2)
 1 + O((x - pi/2)**2, (x, pi/2))
# This result is ok.

>>> sy.series(sy.sin(x),x0=sy.pi/2,n=3)
 1 - (x - pi/2)**2/2 + O((x - pi/2)**3, (x, pi/2))
# This result is ok

>>> sy.series(sy.sin(x),x0=sy.pi/2,n=4)
1 - (x - pi/2)**2/2 + O((x - pi/2)**4, (x, pi/2))
# This result is ok

>>> sy.series(sy.sin(x),x0=sy.pi/2,n=5)
 1 - (x - pi/2)**2/2 + (x - pi/2)**4/24 + O((x - pi/2)**5, (x, pi/2))
# This result is ok
--
In *summary*: 
* there is an error when n=0, i.e., no error: the result should have been given as 1.
* it is also slightly confusing the way the number n of terms is defined -- this definition seems to be different from other tools...
Reply all
Reply to author
Forward
0 new messages