Series expansion

### 12.5.2 Series expansion

The taylor or series command finds Taylor expansions.

- taylor takes one mandatory and four optional arguments:
  - expr, an expression depending on a variable.
  - Optionally, x, the variable (by default x).
  - Optionally n, an integer, the order of the series expansion (by default 5).
  - Optionally, a, the center of the Taylor expansion (by default 0). This can be combined with the optional x by replacing x by x=a.
  - dir, a direction, which can be -1 or 1, for unidirectional series expansion, or 0 (for bidirectional series expansion) (by default 0).
- taylor(expr,x ⟨,a,n,dir ⟩) returns the Taylor expansion of expr about a or order n; consisting of a polynomial in x−a plus a remainder of the form of the form:

  (x−a)n order_size(x−a),

  where order_size is a function such that

  ∀ r>0, |
  lim
  x→ 0
  | xr order_size(x)=0

For regular series expansion, order_size is a bounded function, but for non regular series expansion, it might tend slowly to infinity, for example like a power of ln(x).

#### Example

taylor(sin(x),x=1,2)

or:

series(sin(x),x=1,2)

or (be careful with the order of the arguments):

taylor(sin(x),x,2,1)

or:

series(sin(x),x,2,1)

sin | ⎛ ⎝ | 1 | ⎞ ⎠ | +cos | ⎛ ⎝ | 1 | ⎞ ⎠ | ⎛ ⎝ | x−1 | ⎞ ⎠ | − |
1
2
| sin | ⎛ ⎝ | 1 | ⎞ ⎠ | ⎛ ⎝ | x−1 | ⎞ ⎠ | 2+ | ⎛ ⎝ | x−1 | ⎞ ⎠ | 3 order_size | ⎛ ⎝ | x−1 | ⎞ ⎠

##### Remark.

The order returned by taylor may be smaller than n if cancellations between numerator and denominator occur, for example consider

x3+sin(x)3
x−sin(x)
| .

taylor(x^3+sin(x)^3/(x-sin(x)),x=0,5)

6− |
27
10
| x2+x3+ |
711
1400
| x4+x6 order_size | ⎛ ⎝ | x | ⎞ ⎠

which is only a 2nd degree expansion. Indeed the numerator and denominator valuation is 3, hence you lose 3 orders. To get order 4, you should use n=7.

taylor(x^3+sin(x)^3/(x-sin(x)),x=0,7)

6− |
27
10
| x2+x3+ |
711
1400
| x4− |
737
14000
| x6+x8 order_size | ⎛ ⎝ | x | ⎞ ⎠

a fourth degree expansion.

#### Examples

Find a 4th-order expansion of cos(2x)2 in the vicinity of x=π/6.

taylor(cos(2*x)^2,x=pi/6, 4)

1
4
| − | √ |
3
|  | ⎛ ⎜ ⎜ ⎝ | x− |
π
6
| ⎞ ⎟ ⎟ ⎠ | +2 | ⎛ ⎜ ⎜ ⎝ | x− |
π
6
| ⎞ ⎟ ⎟ ⎠ |
2
| + |
8
3
|  | √ |
3
|  | ⎛ ⎜ ⎜ ⎝ | x− |
π
6
| ⎞ ⎟ ⎟ ⎠ |
3
| − |
8
3
|  | ⎛ ⎜ ⎜ ⎝ | x− |
π
6
| ⎞ ⎟ ⎟ ⎠ |
4
| + | ⎛ ⎜ ⎜ ⎝ | x− |
π
6
| ⎞ ⎟ ⎟ ⎠ |
5
| order_size | ⎛ ⎜ ⎜ ⎝ | x− |
π
6
| ⎞ ⎟ ⎟ ⎠

Find a 5th-order series expansion of arctan(x) in the vicinity of x=+∞.

series(atan(x),x=+infinity,5)

π
2
| − |
1
x
| + |
⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
3
3
| − |
⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
5
5
| + | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
6
| order_size | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠

Note that the expansion variable and the argument of the order_size function is h=1/x → 0 as x→+∞.

Find a 2nd-order expansion of (2x−1)e1/x−1 in the vicinity of x=+∞.

series((2*x-1)*exp(1/(x-1)),x=+infinity,3)

Output (only a 1st-order series expansion):

2 | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
−1
| +1+ |
2
x
| + |
17
6
|  | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
2
| + | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
3
| order_size | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠

Note that this is only a 1st-order expansion. To get a 2nd-order series expansion in 1/x:

series((2*x-1)*exp(1/(x-1)),x=+infinity,4)

2 | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
−1
| +1+ |
2
x
| + |
17
6
|  | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
2
| + |
47
12
|  | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
3
| + | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠ |
4
| order_size | ⎛ ⎜ ⎜ ⎝ |
1
x
| ⎞ ⎟ ⎟ ⎠

Find a 2nd-order series expansion of (2x−1)e1/x−1 in the vicinity of x=-∞.

series((2*x-1)*exp(1/(x-1)),x=-infinity,4)

−2 | ⎛ ⎜ ⎜ ⎝ | − |
1
x
| ⎞ ⎟ ⎟ ⎠ |
−1
| +1+ |
2
x
| + |
17
6
|  | ⎛ ⎜ ⎜ ⎝ | − |
1
x
| ⎞ ⎟ ⎟ ⎠ |
2
| − |
47
12
|  | ⎛ ⎜ ⎜ ⎝ | − |
1
x
| ⎞ ⎟ ⎟ ⎠ |
3
| + | ⎛ ⎜ ⎜ ⎝ | − |
1
x
| ⎞ ⎟ ⎟ ⎠ |
4
| order_size | ⎛ ⎜ ⎜ ⎝ | − |
1
x
| ⎞ ⎟ ⎟ ⎠

Find a 2nd-order series expansion of (1+x)1/x/x3 in the vicinity of x=0+.

series((1+x)^(1/x)/x^3,x=0,2,1)

(Note that this is a one-sided series expansion, since dir=1.)

e x−3− |
e
2
| x−2+x−1 order_size | ⎛ ⎝ | x | ⎞ ⎠