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 ff is as follows.

n=0f(n)(a)n!(xa)n=f(a)+f(a)(xa)+f(a)2!(xa)2+ \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, ff and its Taylor series are indeed the same.

f(x)=n=0f(n)(a)n!(xa)n=f(a)+f(a)(xa)+f(a)2!(xa)2+ 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 ff 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\sin as an example. It’s not easy to calculate the function values of such transcendental functions. When the values of sinx\sin x are easily known for special angles like xx, 00, π6\dfrac{\pi}{6}, etc., it’s straightforward. But calculating quasi-arbitrary values such as sin0.672\sin 0.672 can be difficult. In such cases, we can approximate the value using the Taylor series of sin\sin. The Taylor series of sin\sin is as follows.

sinx=xx33!+x55!x77!+=n=0(1)nx2n+1(2n+1)! \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 sin0.672\sin 0.672 with appropriate multiplications and additions.

sinxxx33!+x55!x77! \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 sinx\sin x and s6=n=06(1)nx2n+1(2n+1)!s_{6} = \displaystyle \sum\limits_{n=0}^{6} (-1)^{n} \dfrac{x^{2n+1}}{(2n+1)!} in the interval [0,π/4][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.

tan1x=n=0(1)nx2n+12n+1 \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=1x = 1.

π4=tan11=113+1517+ \dfrac{\pi}{4} = \tan^{-1} 1 = 1 - \dfrac{1}{3} + \dfrac{1}{5} - \dfrac{1}{7} + \cdots

    π=4(113+1517+) \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)=sinxx2f(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\sin.

sinxx2dx=1x2n=0(1)nx2n+1(2n+1)!dx=1x2(xx33!+x55!x77!+)dx=(1xx3!+x35!x57!+)dx=C+lnxx223!+x445!x667!+=C+lnx+n=1(1)nx2n2n(2n+1)! \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 ex2e^{x^{2}}. Integrating ex2e^{x^{2}} means, according to the fundamental theorem of calculus, finding a function that differentiates to ex2e^{x^{2}}. Finding such a function is difficult due to the exponent x2x^{2} included. In such cases, it’s easier to represent ex2e^{x^{2}} as a power series and integrate indefinitely.

ex2dx=(1+x2+x42!++x2nn!+)dx=C+x+x331!+x552!+x773!++x2n+1(2n+1)n!+=C+n=0x2n+1(2n+1)n! \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)=a0+a1x+a2x2+V(x) = a_{0} + a_{1}x + a_{2}x^{2} + \cdots, which can be used to derive Hooke’s law F(x)=kxF(x) = -kx and the equation of motion of a simple harmonic oscillator x¨+kxx=0\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.

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

Jν(x)=n=0(1)nΓ(n+1)Γ(n+ν+1)(x2)2n+ν 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}