Taylor series

In your first calculus course, you are aware that a Taylor series can be written about any point, and you learned about Taylor series for functions such as $\sin(x)$ and $\cos(x)$. The function series(...) takes an expression and creates a Taylor series about a given point. As you will recall, for sufficiently well-behaved functions, as an example:

$f(x) = f(x_0) + f^{(1)}(x_0)(x - x_0) + \frac{1}{2!}f^{(2)}(x_0)(x - x_0)^2 + \frac{1}{3!}f^{(1)}(x_0)(x - x_0)^3 + \frac{1}{4!}f^{(4)}(\xi)(x - x_0)^4$

The value $\xi$ is some $x_0 \le \xi \le x$.

If the point we are expanding about is $x_0 = 0$, this simplifies to

$f(x) = f(0) + f^{(1)}(0)x + \frac{1}{2!}f^{(2)}(0)x^2 + \frac{1}{3!}f^{(1)}(0)x^3 + \frac{1}{4!}f^{(4)}(\xi)x^4$

where $0 \le \xi \le x$.

In Maple, you can provide the expression, and the point around which to expand, as well as the order of the error term:

[> series( sin( x ), x = 0, 10 );

$x - \frac{1}{6}x^3 + \frac{1}{120}x^5 - \frac{1}{5040}x^7 + \frac{1}{362880}x^9 + \textrm{O}(x^{11})$

[> series( sin( x ), x = 1, 5 );

$\sin(1) + \cos(1)(x - 1) - \frac{1}{2}\sin(1)(x - 1)^2 - \frac{1}{6}\cos(1)(x - 1)^3 + \frac{1}{24}\sin(1)(x - 1)^4 + \textrm{O}((x - 1)^5)$

In some of your courses, you will focus on an expansion around a point $x$, and you'd like to approximate the function some small distance $h$ from this point. This, too, can be done in Maple:

[> series( f( x + h ), h = 0, 5 );

$f(x) + \textrm{D}(f)(x) h + \frac{1}{2} \textrm{D}^{(2)}(f)(x) h^2 + \frac{1}{6} \textrm{D}^{(3)}(f)(x) h^3 + \frac{1}{24} \textrm{D}^{(4)}(f)(x) h^4 + \textrm{O}(h^5)$

Now, one issue with this is that this creates a series(...) data structure, and a serious problem with this data structure is that it is poorly integrated into the rest of the library. For example, there is no way to combine two series into one, there is no way to combine an expression and a series. Consequently, it usually makes sense to convert a series into an expression, or more specifically, a polynomial.

A series can be converted into a polynomial by passing it as an argument to convert(...) where the second argument specifies the conversion: in this case, a 'polynom'.

[> convert( series( f( x + h ), h = 0, 5 ), 'polynom' );

$f(x) + \textrm{D}(f)(x) h + \frac{1}{2} \textrm{D}^{(2)}(f)(x) h^2 + \frac{1}{6} \textrm{D}^{(3)}(f)(x) h^3 + \frac{1}{24} \textrm{D}^{(4)}(f)(x) h^4$

Now, two functions that are aware of the series(...) data structure are differentiation and indefinite integration; for example, the second derivative of $\sin(x)$ is $-\sin(x)$, and we see that in the Taylor series:

[> sins := series( sin( x ), x = 0, 10 );

$x - \frac{1}{6}x^3 + \frac{1}{120}x^5 - \frac{1}{5040}x^7 + \frac{1}{362880}x^9 + \textrm{O}(x^{11})$

[> diff( sins, x, x );

$-x + \frac{1}{6}x^3 - \frac{1}{120}x^5 + \frac{1}{5040}x^7 + \textrm{O}(x^{9})$

You will note that the error term is of higher order now.