#calculus #mathematic
Created at 2022-12-20
# [Anonymous feedback](https://www.admonymous.co/louis030195)
# [[Epistemic status]]
#shower-thought #to-digest
# Related
# TODO
> [!TODO] TODO
# Taylor series
$\sum_{n=0}^{\infty}\frac{f^{(n)}(a)}{n!}(x-a)^n$

Taylor series is a representation of a function as an infinite sum of terms. The terms are calculated using derivatives of the function, evaluated at a single point. The Taylor series of a function is typically used to approximate the function near that point and can be used to approximate functions in the entire domain of the function. Taylor series can be used for a variety of applications such as approximating solutions to differential equations and numerical integration.
<iframe width="560" height="315" src="https://www.youtube.com/embed/3d6DsjIBzJ4" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
## Taylor Series in Python & Examples
```py
import math
def taylor_series(x, n):
"""
This function calculates the Taylor series of a given function.
:param x: the point to calculate the Taylor series of
:param n: the number of terms in the Taylor series
:return: the Taylor series approximation of the given function
"""
# Initialize the Taylor series
taylor_series = 0
# Calculate each term in the Taylor series
for i in range(n):
taylor_series += (x**i) / math.factorial(i)
return taylor_series
```
Examples:
Calculate the Taylor series of e^x at x = 0 with 10 terms:
```py
taylor_series(0, 10) # returns 1.0
```
Calculate the Taylor series of sin(x) at x = 0 with 10 terms:
```py
taylor_series(0, 10) # returns 0.0
```