# Taylor series
A continuous function $f(x)$ (with $f^n(x)$ exist and $f^{n+1}(x)$ continuous) can be expanded in the form of a Taylor series:
\begin{eqnarray}
f(x) &=& \sum_{n=0}^\infty \frac{f^n(a)}{n!}(x-a)^n \\
&=& f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \cdots + \frac{f^{(k)}(a)}{k!}(x-a)^k + h_k(x)(x-a)^k
\end{eqnarray}
$\lim_{x\to a}h_k(x)=0$. This is called the Peano form of the remainder.

Clearly, since many derivatives are involved, a Taylor series expansion is only possible when the function is so smooth that it can be differentiated again and again. An infinite-order polynomial can yield an error-free approximation.

## Trigonometric function
Trigonometric functions are continuous and $n$th-order differentiable, there taylor series can be represented as:
\begin{equation}
 cos(x)= \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!}x^{2n}
\end{equation}
\begin{equation}
 sin(x)= \sum_{n=0}^\infty \frac{(-1)^n}{(2n+1)!}x^{2n+1}
\end{equation}


```python
import math as m
import numpy as np
import matplotlib.pyplot as plt

def Plot(n, X, ORG, APPR, FOMU):
    plt.figure(figsize=(10,5))
    plt.xlim(-4*np.pi,4*np.pi)
    plt.ylim(-5,5)
    ax = plt.gca()
    ax.grid(color='#b7b7b7', linestyle='-', linewidth=0.5, alpha=0.5)
    ax.text(-12,4,FOMU + ', n='+str(n),fontsize=12,color='#000000')
    plt.plot(X, ORG, '-', color='black', lw=2)
    plt.plot(X, APPR, '-', color='#d3d3d3', lw=2)
    plt.xticks([-4*m.pi, -2*m.pi, 0, 2*m.pi, 4*m.pi], [r'$-4\pi$', r'$-2\pi$', r'$0$',r'$2\pi$', r'$4\pi$'])

def Series(n):
    APPR_SIN = 0
    APPR_COS = 0
    # FOMULA
    FOMU_SIN = '$\sum_{n=0}^\infty {(-1)^n}x^{2n+1}/{(2n+1)!}$'
    FOMU_COS = '$\sum_{n=0}^\infty {(-1)^n}x^{2n}/{(2n)!}$'
    X = np.arange(-4*np.pi,4*np.pi, 8*np.pi/1000)
    SIN = np.sin(X)
    COS = np.cos(X)
    
    for i in range(n+1):
        APPR_SIN = APPR_SIN + (-1)**(i)*((X)**(2*i+1))/m.factorial(2*i+1)
        APPR_COS = APPR_COS + (-1)**(i)*((X)**(2*i))/m.factorial(2*i)
    # SIN
    Plot(n,X,SIN,APPR_SIN, FOMU_SIN)
    # COS
    Plot(n,X,COS,APPR_COS, FOMU_COS)
    
Series(10)
```

Since $e^x$ is its own derivative, the Taylor series expansion for $f(x) = e^x$ is one of the simplest imaginable infinite series:
\begin{equation}
e^{x} = \sum_{n=0}^\infty \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \cdots
\end{equation}
We can easily generalize this formula to complex number:
\begin{eqnarray}
 e^{ix} = \sum_{n=0}^\infty \frac{(ix)^n}{n!} &=& 1 + ix + \frac{(ix)^2}{2!} + \frac{(ix)^3}{3!} + \cdots \\
 &=& 1 + ix - \frac{x^2}{2!} - \frac{ix^3}{3!} +\cdots \\
 &=& \left( 1 - \frac{x^2}{2!} + \cdots \right) + i\left( x - \frac{x^3}{3!} + \cdots \right) \\
\end{eqnarray}
where:
\begin{equation}
real\left\{e^{ix}\right\} =  1 - \frac{x^2}{2!} +  \frac{x^4}{4!} - \cdots
\end{equation}
\begin{equation}
imag\left\{e^{ix}\right\} =  x - \frac{x^3}{3!} +  \frac{x^5}{5!} - \cdots
\end{equation}
Recall cos and sin series:
\begin{equation}
 cos(x)= \sum_{n=0}^\infty \frac{(-1)^n}{(2n)!}x^{2n}
\end{equation}
\begin{equation}
 sin(x)= \sum_{n=0}^\infty \frac{(-1)^n}{(2n+1)!}x^{2n+1}
\end{equation}
We got the most beautiful formula of all time (known as Euler's formula):
\begin{equation}
e^{ix} = cos(x) + isin(x)
\end{equation}
Which establishes the fundamental relationship between the trigonometric functions and the complex exponential function.

## Reference:

- [Mathematics of the discrete Fourier transform](https://ccrma.stanford.edu/~jos/st/)
- [Taylor series - Wikipedia](https://en.wikipedia.org/wiki/Taylor_series)
- [Euler's formula - Wikipedia](https://en.wikipedia.org/wiki/Euler%27s_formula)
- [Intuitive Understanding Of Euler’s Formula](https://betterexplained.com/articles/intuitive-understanding-of-eulers-formula/)
- [3Blue1Brown - YouTube](https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw)

ba3df04d0d13d3a896c916decc5efc128884d2ba
ipynb
Jupyter Notebook
001_taylor_series.ipynb
ValleyZw/hill
51d4bc76d7c49b3dccf88659fade806906a9b4e2
MIT
2019-07-22T07:19:39.000Z
2019-07-22T07:19:39.000Z
001_taylor_series.ipynb
ValleyZw/hill
51d4bc76d7c49b3dccf88659fade806906a9b4e2
MIT
001_taylor_series.ipynb
ValleyZw/hill
51d4bc76d7c49b3dccf88659fade806906a9b4e2
MIT
2020-05-19T17:52:16.000Z
2020-05-19T17:52:16.000Z
Qwen/Qwen-72B
1. YES
2. YES