Maclaurin and Taylor Series

← Numerical Methods

Source inspiration: (Mathew 2000-2019).

Description

Taylor Series is an infinite sum of monomial terms. Taylor series acts like a polynomial with infinite terms. The series about \(x_0\) converges for \(|x-x_0|<R\) and diverges for \(|x-x_0|>R\), where the radius of convergence \(R\) is the distance from \(x_0\) to the nearest singularity of \(f\) in the complex plane. Asymptotes and growth rate on the real line do not decide it. \(\arctan(x)\) (M13) and \(1/(1+x^2)\) (M05) are smooth on the whole real line but have singularities at \(\pm i\), so \(R=1\) about 0; \(\tanh(x)\) has poles at \(\pm i\pi/2\), so \(R=\pi/2\) about 0; \(\log(x)\) about 1 (T04) has \(R=1\) because of the singularity at \(x=0\). Functions with no singularities, such as \(\exp(x)\), \(\sin(x)\), \(e^{-x^2/2}\), \(J_0(x)\) and the normal CDF, have \(R=\infty\), whether or not they have horizontal asymptotes. The normal CDF (M18 below) has two horizontal asymptotes like \(\tanh(x)\), and its order-10 polynomial pulls away from it beyond about \(|x|=2\), but only because order 10 is too low: at \(x=3\) the order-10 value is 2.0006 and the order-40 value is within \(2\times10^{-7}\) of the true 0.99865.

Maclaurin and Taylor polynomials approximate a smooth function locally by truncating a power series. For center \(x_0\), the degree-\(n\) Taylor polynomial is

\[ T_n(x)=\sum_{k=0}^{n}\frac{f^{(k)}(x_0)}{k!}(x-x_0)^k. \]

The Maclaurin polynomial is the special case \(x_0=0\). Near singularities or non-smooth points, series may converge locally but fail globally.

Taylor’s theorem gives the error as a general result: if \(f\) has \(n+1\) continuous derivatives on an interval containing \(x_0\) and \(x\), then

\[ f(x)=T_n(x)+E_n(x),\qquad E_n(x)=\frac{f^{(n+1)}(c)}{(n+1)!}(x-x_0)^{n+1} \]

for some \(c\) between \(x_0\) and \(x\); this is the Lagrange form of the remainder, as Mathews states it. The error is therefore \(O\big((x-x_0)^{n+1}\big)\) as \(x\to x_0\) (see Big “O” Truncation Error).

A strong understanding of the Taylor series helps understand many numerical methods. Taylor series is often used in numerical methods to describe “the order of accuracy” or “order of convergence” of a particular numerical method. For instance, in numerical integration, a composite rule that integrates the constant and linear Taylor terms exactly, but not the quadratic term, is second-order accurate; the trapezoidal rule is an example.

A Taylor series is a special case of a power series. A related series is the Laurent series, which also allows negative powers of \((x-x_0)\). Padé approximant is very similar to a truncated Taylor series but is instead a ratio of two polynomials. Laurent Series and Padé Approximation have their own pages, and Taylor polynomials drive the Taylor Series Method for ODEs.

Video Animations

This section keeps some video animations I created before generated the GIFs. They have a different aesthetic than the GIFs. The videos are generated by a MATLAB script:

taylor_series_animation_code.m

Exponential Cases, \(exp(x)\) about 0 and 1

The Taylor series of \(exp(x)\) about 0 has an infinite radius of convergence. Higher and higher-order Taylor series truncations converge more and more to \(exp(x)\). \(exp(x)\) about 1 is similar to \(exp(x)\) about 0, except that the expansion point is 1.

Sine Cases, \(sin(x)\) about 0 and 0.5

Sine has no singularities in the complex plane, so its Taylor series converges for every \(x\); the radius of convergence is infinite.

Hyperbolic Tangent Cases, \(tanh(x)\) about 0 and 0.5

Tanh has two horizontal asymptotes, but what limits the radius of convergence is its poles at \(\pm i\pi/2\): the radius is \(\pi/2\approx1.571\) about 0 and \(\sqrt{0.25+\pi^2/4}\approx1.648\) about 0.5.

Inverse Tangent Cases, \(arctan(x)\) about 0 and 0.5

arctan also has two horizontal asymptotes; its radius of convergence is limited by its singularities at \(\pm i\): 1 about 0 and \(\sqrt{1.25}\approx1.118\) about 0.5.

Rational and Singular Cases, \(1/x\) about 0.5 and \(1/(x-1)\) about 0.75

Non-Smooth Case, \(sqrt(abs(x))*sign(x)\) about 0.5

This function is built from abs, which is continuous but has a corner at x=0, and sign, which jumps at x=0; the composite itself is continuous. This function often is used by engineers to simulate lump parameter fluid flow. This function is a poor choice because the sqrt gives it an infinite derivative at x=0, so the Taylor series about 0.5 has radius 0.5. The Taylor series cannot converge across x=0.

Animations

Each animation steps through the Taylor polynomials one order per frame, one frame per second, showing the current order (blue) and, from order 1 on, the previous order (gray) over the target function (magenta); the red dot marks \((x_0, f(x_0))\). Parts of a polynomial outside the plotted \(y\)-range are drawn along the top or bottom edge.

All 31 GIFs on this page are generated by one Julia script:

Julia source for all cases

Maclaurin Cases (18)

M01 - \(f(x)=\dfrac{1}{1-x}\), \(x_0=0\), \(x\in[-1.5,1.5]\)

Maclaurin animation for one over one minus x centered at zero.

M02 - \(f(x)=\dfrac{1}{1+x}\), \(x_0=0\), \(x\in[-1.5,1.5]\)

Maclaurin animation for one over one plus x centered at zero.

M03 - \(f(x)=\dfrac{1}{(1-x)^2}\), \(x_0=0\), \(x\in[-1.5,1.5]\)

Maclaurin animation for one over the square of one minus x, centered at zero.

M04 - \(f(x)=\dfrac{1}{\sqrt{1-x}}\), \(x_0=0\), \(x\in[-1.5,1.5]\)

Maclaurin animation for one over square root of one minus x centered at zero.

M05 - \(f(x)=\dfrac{1}{1+x^2}\), \(x_0=0\), \(x\in[-1.5,1.5]\)

Maclaurin animation for one over one plus x squared centered at zero.

M06 - \(f(x)=\log(1+x)\), \(x_0=0\), \(x\in[-1.5,1.5]\)

Maclaurin animation for log of one plus x centered at zero.

M07 - \(f(x)=\sin(x)\), \(x_0=0\), \(x\in[-3\pi,3\pi]\)

Maclaurin animation for sine centered at zero.

M08 - \(f(x)=\cos(x)\), \(x_0=0\), \(x\in[-3\pi,3\pi]\)

Maclaurin animation for cosine centered at zero.

M09 - \(f(x)=\tan(x)\), \(x_0=0\), \(x\in[-\pi,\pi]\)

Maclaurin animation for tangent centered at zero.

M10 - \(f(x)=e^{x}\), \(x_0=0\), \(x\in[-2,3]\)

Maclaurin animation for exponential of x centered at zero.

M11 - \(f(x)=e^{-x}\cos(x)\), \(x_0=0\), \(x\in[-2,4]\)

Maclaurin animation for e to the minus x times cosine x centered at zero.

M12 - \(f(x)=\cosh(x)\), \(x_0=0\), \(x\in[-4,4]\)

Maclaurin animation for hyperbolic cosine centered at zero.

M13 - \(f(x)=\arctan(x)\), \(x_0=0\), \(x\in[-2,2]\)

Maclaurin animation for arctangent centered at zero.

M14 - \(f(x)=\arcsin(x)\), \(x_0=0\), \(x\in[-1.5,1.5]\)

Maclaurin animation for arcsine centered at zero.

M15 - \(f(x)=J_0(x)\), \(x_0=0\), \(x\in[-10.2,10.2]\)

Maclaurin animation for Bessel J zero centered at zero.

M16 - \(f(x)=J_1(x)\), \(x_0=0\), \(x\in[-10.2,10.2]\)

Maclaurin animation for Bessel J one centered at zero.

M17 - \(f(x)=\dfrac{1}{\sqrt{2\pi}}e^{-x^2/2}\), \(x_0=0\), \(x\in[-3,3]\)

Maclaurin animation for the normal density centered at zero.

M18 - \(f(x)=\dfrac{1}{2}+\dfrac{1}{2}\operatorname{erf}\!\left(\dfrac{x}{\sqrt{2}}\right)\), \(x_0=0\), \(x\in[-3,3]\)

Maclaurin animation for the normal CDF centered at zero.

Taylor Cases (13)

T01 - \(f(x)=\sqrt{x}\), \(x_0=1\), \(x\in[0,10.5]\)

Taylor animation for square root of x centered at one.

T02 - \(f(x)=\sqrt{x}\), \(x_0=4\), \(x\in[0,10.5]\)

Taylor animation for square root of x centered at four.

T03 - \(f(x)=\sqrt{x}\), \(x_0=5\), \(x\in[0,10.5]\)

Taylor animation for square root of x centered at five.

T04 - \(f(x)=\log(x)\), \(x_0=1\), \(x\in[-0.5,4.1]\)

Taylor animation for log x centered at one.

T05 - \(f(x)=\log(x)\), \(x_0=2\), \(x\in[-0.5,4.1]\)

Taylor animation for log x centered at two.

T06 - \(f(x)=\sin(x)\), \(x_0=\pi/4\), \(x\in[-7\pi/4,9\pi/4]\)

Taylor animation for sine centered at pi over four.

T07 - \(f(x)=\cos(x)\), \(x_0=\pi/3\), \(x\in[-5\pi/3,7\pi/3]\)

Taylor animation for cosine centered at pi over three.

T08 - \(f(x)=\Gamma(x)\), \(x_0=1\), \(x\in[-0.2,5.2]\)

Taylor animation for Gamma function centered at one.

T09 - \(f(x)=\Gamma(x)\), \(x_0=2\), \(x\in[-0.2,5.2]\)

Taylor animation for Gamma function centered at two.

T10 - \(f(x)=\Gamma(x)\), \(x_0=3\), \(x\in[-0.2,5.2]\)

Taylor animation for Gamma function centered at three.

T11 - \(f(x)=Y_0(x)\), \(x_0=10\), \(x\in[0,22]\)

Taylor animation for Bessel Y zero centered at ten.

T12 - \(f(x)=Y_0(x)\), \(x_0=5\), \(x\in[0,22]\)

Taylor animation for Bessel Y zero centered at five.

T13 - \(f(x)=Y_0(x)\), \(x_0=2\), \(x\in[0,22]\)

Taylor animation for Bessel Y zero centered at two.

References

Mathew, John H. 2000-2019. Numerical Analysis - Numerical Methods Modules. https://web.archive.org/web/20190808102217/http://mathfaculty.fullerton.edu/mathews/n2003/NumericalUndergradMod.html.