logo

Applications of Taylor Series 📂Calculus

Applications of Taylor Series

Explanation

Taylor series (Maclaurin series) is an approximation of a given function as a power series, and the Taylor series of function $f$ is as follows.

$$ \sum\limits_{n=0}^{\infty} \dfrac{f^{(n)}(a)}{n!} (x-a)^{n} = f(a) + f^{\prime}(a)(x-a) + \dfrac{f^{\prime \prime}(a)}{2!} (x-a)^{2} + \cdots $$

Under good conditions, $f$ and its Taylor series are indeed the same.

$$ f(x) = \sum\limits_{n=0}^{\infty} \dfrac{f^{(n)}(a)}{n!} (x-a)^{n} = f(a) + f^{\prime}(a)(x-a) + \dfrac{f^{\prime \prime}(a)}{2!} (x-a)^{2} + \cdots $$

Although the Taylor series involves limits and may seem more difficult at first glance, it is actually not. In cases where function $f$ is complex, it may be more convenient to deal with it using the Taylor series. Essentially, the Taylor series is (an infinite-degree) polynomial, making differentiation, integration, and function value calculation easier.

Let’s look into how expressing functions as power series is useful in various situations.

Function Value Approximation

Consider the sine function $\sin$ as an example. It’s not easy to calculate the function values of such transcendental functions. When the values of $\sin x$ are easily known for special angles like $x$, $0$, $\dfrac{\pi}{6}$, etc., it’s straightforward. But calculating quasi-arbitrary values such as $\sin 0.672$ can be difficult. In such cases, we can approximate the value using the Taylor series of $\sin$. The Taylor series of $\sin$ is as follows.

$$ \sin x = x - \dfrac{x^{3}}{3!} + \dfrac{x^{5}}{5!} - \dfrac{x^{7}}{7!} + \cdots = \sum\limits_{n=0}^{\infty} (-1)^{n} \dfrac{x^{2n+1}}{(2n+1)!} $$

Thus, using the following approximation formula, one can easily calculate the value of $\sin 0.672$ with appropriate multiplications and additions.

$$ \sin x \approx x - \dfrac{x^{3}}{3!} + \dfrac{x^{5}}{5!} - \dfrac{x^{7}}{7!} $$

In fact, transcendental functions are often approximated and implemented using Taylor series in programming languages. For example, in Julia, examining the code reveals that the sine function is approximated up to the 7th term of the Taylor series.

By defining the function directly with constants and calculating, one can get almost the same values as the sine function implemented in Julia.

julia> function mysin(x)
           S = [-1.66666666666666324348e-01,
                8.33333333332248946124e-03,
                -1.98412698298579493134e-04,
                2.75573137070700676789e-06,
                -2.50507602534068634195e-08,
                1.58969099521155010221e-10]
           sinx = x +  S[1]*x^3 + S[2]*x^5 + S[3]*x^7 + S[4]*x^9 + S[5]*x^11 + S[6]*x^13
           return sinx
       end
mysin (generic function with 1 method)

julia> sin(0.672)
0.622552387351666

julia> mysin(0.672)
0.6225523873516658

Comparing $\sin x$ and $s_{6} = \displaystyle \sum\limits_{n=0}^{6} (-1)^{n} \dfrac{x^{2n+1}}{(2n+1)!}$ in the interval $[0, \pi/4]$ shows there’s practically no difference.

S = [-1.66666666666666324348e-01,
         8.33333333332248946124e-03,
         -1.98412698298579493134e-04,
         2.75573137070700676789e-06,
         -2.50507602534068634195e-08,
         1.58969099521155010221e-10]

x = 0:0.01:π/4
y = sin.(x)
s₆ = x .+ S[1]*x.^3 .+ S[2]*x.^5 .+ S[3]*x.^7 .+ S[4]*x.^9 .+ S[5]*x.^11 .+ S[6]*x.^13

using Plots
plot(x, y, label="sin(x)", linewidth=8, dpi=300, size=(728,300))
plot!(x, s₆, label="s_6", linewidth=3, ls=:dash, lc=:red)

Irrational Number Approximation

Calculating trigonometric functions is difficult, and calculating inverse trigonometric functions is even more so. The function values of arctangent can be approximated using the Taylor series of arctangent.

$$ \tan^{-1} x = \sum\limits_{n=0}^{\infty} (-1)^{n} \dfrac{x^{2n+1}}{2n+1} $$

We can derive an interesting formula from the above equation by substituting $x = 1$.

$$ \dfrac{\pi}{4} = \tan^{-1} 1 = 1 - \dfrac{1}{3} + \dfrac{1}{5} - \dfrac{1}{7} + \cdots $$

$$ \implies \pi = 4 \left( 1 - \dfrac{1}{3} + \dfrac{1}{5} - \dfrac{1}{7} + \cdots \right) $$

Thus, we obtain a series that can approximate irrational number $\pi$.

Integration

Expressing functions as Taylor series is advantageous not only for calculating function values but also for integration. This should be clear because Taylor series are polynomials. Integrating polynomials is very easy, so complex functions can be simplified by expressing them as Taylor series for integration. For example, the indefinite integral of a function like $f(x) = \dfrac{\sin x}{x^{2}}$ is difficult to find. (Though integration by parts comes to mind, actually doing it gets you stuck.) In such cases, it is easier to integrate the Taylor series of $\sin$.

$$ \begin{align*} \int \dfrac{\sin x}{x^{2}} dx &= \int \dfrac{1}{x^{2}} \sum\limits_{n=0}^{\infty} (-1)^{n} \dfrac{x^{2n+1}}{(2n+1)!} dx \\ &= \int \dfrac{1}{x^{2}} \left( x - \dfrac{x^{3}}{3!} + \dfrac{x^{5}}{5!} - \dfrac{x^{7}}{7!} + \cdots \right) dx \\ &= \int \left( \dfrac{1}{x} - \dfrac{x}{3!} + \dfrac{x^{3}}{5!} - \dfrac{x^{5}}{7!} + \cdots \right) dx \\ &= C + \ln |x| - \dfrac{x^{2}}{2 \cdot 3!} + \dfrac{x^{4}}{4 \cdot 5!} - \dfrac{x^{6}}{6 \cdot 7!} + \cdots \\ &= C + \ln |x| + \sum\limits_{n=1}^{\infty} (-1)^{n} \dfrac{x^{2n}}{2n(2n+1)!} \end{align*} $$

Another example is a function like $e^{x^{2}}$. Integrating $e^{x^{2}}$ means, according to the fundamental theorem of calculus, finding a function that differentiates to $e^{x^{2}}$. Finding such a function is difficult due to the exponent $x^{2}$ included. In such cases, it’s easier to represent $e^{x^{2}}$ as a power series and integrate indefinitely.

$$ \begin{align*} \int e^{x^{2}} dx &= \int \left( 1+x^2+\dfrac{x^4}{2!}+\cdots +\dfrac{x^{2n}}{n!}+\cdots \right) dx \\ &= C + x + \dfrac{x^3}{3 \cdot 1!} + \dfrac{x^5}{5 \cdot 2!}+\dfrac{x^7}{7 \cdot 3!}+ \cdots + \dfrac{x^{2n+1}}{(2n+1)n!} + \cdots \\ &= C + \sum \limits_{n=0}^\infty \dfrac{x^{2n+1}}{(2n+1)n!} \end{align*} $$

Harmonic Oscillator

Representing arbitrary functions as power series is applied in various fields. In physics, the potential energy of a simple harmonic oscillator is given by a series like $V(x) = a_{0} + a_{1}x + a_{2}x^{2} + \cdots$, which can be used to derive Hooke’s law $F(x) = -kx$ and the equation of motion of a simple harmonic oscillator $\ddot{x} + \dfrac{k}{x}x = 0$.

Solution of Differential Equations

Some differential equations have solutions expressed as power series. The Bessel differential equation and its solution (Bessel functions) are as follows.

$$ x^2 y^{\prime \prime} +xy^{\prime} +(x^2-\nu^2)y = 0 $$

$$ J_{\nu}(x)=\sum \limits_{n=0}^{\infty} \frac{(-1)^{n} }{\Gamma (n+1) \Gamma (n+\nu+1)} \left(\frac{x}{2} \right)^{2n+\nu} $$