MATLAB: Is the Taylor series result displayed in wrong order when using TAYLOR in Symbolic Math Toolbox 3.2.3 (R2008a)

Symbolic Math Toolbox

In expressions with an inessential singularity TAYLOR results in an incorrect expansion. In the example code below, apparently TAYLOR expands the numerator to the required order and then divides by "x^2", instead of computing the taylor expansion for the entire expression. Result vs. expected result:
taylor( (x^3 + x^5)/x^2, 4, x, 0 )
taylor( (x^3 + x^5)/x^2, 5, x, 0 )
taylor( (x^3 + x^5)/x^2, 6, x, 0 )
result 1: x expected: x+x^3
result 2: x expected: x+x^3
result 3: x+x^3 expected: x+x^3

Best Answer

This behaviour is due to Maple. Maple's TAYLOR command actually behaves as described in the Maple documentation, which includes these parts (in series and order):
- If the third argument n is present then it specifies the "truncation order'' of the series calculations. This does not mean the truncation order of the actual series. See Order for more information about this.
- The environment variable Order represents the order of series calculations performed by Maple. It does not represent the order of the series output. In the given example, note that the order of the series expansion of exp(x)/x is only 7 rather than 8, since the series expansion of exp(x) is divided by x, thereby reducing the degree by 1.
To work around this behaviour calling TAYLOR with higher order approximations changes the behavior of future low-order approximations. For example:
t = maple('taylor','(x^3+x^5)/x^2','x=0','4')
t =
series(1*x+O(x^3),x,3)
t = maple('taylor','(x^3+x^5)/x^2','x=0','7')
t =
series(1*x+1*x^3,x)
t = maple('taylor','(x^3+x^5)/x^2','x=0','4')
t =
series(1*x+1*x^3,x)
So the workaround would be to perform some high order approximations before computing the order you really care about.