Some observations on functions

After looking at numbers, we will continue with a few practical observations about functions. The Taylor series of a real or complex-valued function f(x) that is infinitely differentiable at a real or complex number a is the power series:

\displaystyle f(x) = f(a) + \frac{f'(a)}{1!} (x-a) + \frac{f''(a)}{2!} (x-a)^2 + \frac{f'''(a)}{3!} (x-a)^3 + \cdots
\displaystyle = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!} (x-a)^{n}

Using a = 0, we obtain the so-called Maclaurin series:

\displaystyle f(x) = f(0) + \frac{f'(0)}{1!} x + \frac{f''(0)}{2!} x^2 + \frac{f'''(0)}{3!} x^3 + \cdots
\displaystyle = \sum_{n=0}^{\infty} \frac{f^{(n)}(0)}{n!} x^{n}

The series above are clearly “power series” since we could write them as:

\displaystyle a_0 + a_1 (x-a) + a_2 (x-a)^2 + a_3 (x-a)^3 + \cdots

and

\displaystyle a_0 + a_1 x + a_2 x^2 + a_3 x^3 + \cdots

respectively, using the definition a_n = \frac{f^{(n)}(a)}{n!} for the Taylor series or a_n = \frac{f^{(n)}(0)}{n!} for the Maclaurin series.

The Taylor series of a polynomial is the polynomial itself.

Taylor and Maclaurin series can be used in a practical way to program functions in a calculating machine or computer. A function such as \texttt{cos(x)} or \texttt{sin(x)} etc. has no meaning for a computer. For a computer, \texttt{cos(x)} and \texttt{sin(x)} are just symbols with no explicit algorithm defined to compute numerical results. Here are some Maclaurin series of important functions:

\displaystyle \frac{1}{1-x} = \sum_{n=0}^{\infty} x^n, \quad x \in (-1,1)
\displaystyle \frac{1}{(1-x)^2} = \sum_{n=1}^{\infty} n x^{n-1}, \quad x \in (-1,1)
\displaystyle \frac{1}{(1-x)^3} = \sum_{n=2}^{\infty} \frac{(n-1)n}{2} x^{n-2}, \quad x \in (-1,1)
\displaystyle e^{x} = \sum_{n=0}^{\infty} \frac{x^n}{n!}
\displaystyle = \frac{x^0}{0!} + \frac{x^1}{1!} + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \frac{x^5}{5!} + \cdots
\displaystyle = 1 + x + \frac{x^2}{2} + \frac{x^3}{6} + \frac{x^4}{24} + \frac{x^5}{120} + \cdots, \quad x \in \mathbb{R}
\displaystyle \ln(1+x) = \sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} x^{n}
\displaystyle = x - \frac{x^2}{2} + \frac{x^3}{3} - \frac{x^4}{4} + \cdots, \quad x \in (-1,1]
\displaystyle \sin x = \sum_{n=0}^{\infty} \frac{(-1)^n}{(2n+1)!} x^{2n+1}
\displaystyle = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \frac{x^9}{9!} - \frac{x^{11}}{11!} + \cdots, \quad x \in \mathbb{R}
\displaystyle \cos x = \sum_{n=0}^{\infty} \frac{(-1)^n}{(2n)!} x^{2n}
\displaystyle = 1 - \frac{x^2}{2!} + \frac{x^4}{4!} - \frac{x^6}{6!} + \frac{x^8}{8!} - \frac{x^{10}}{10!} + \cdots, \quad x \in \mathbb{R}

For programming the sine function we could use, for example, the series above as follows (in Python):


def sin(x):
    epsilon = 1e-16
    term = x
    sine = x
    sign = -1
    n = 1
    while abs(term) > epsilon:
        term *= x * x / ((2 * n) * (2 * n + 1))
        sine += sign * term
        sign *= -1
        n += 1
    return sine

Comments

Leave a comment