---
### 테일러 전개

 - 원래의 형태와 비슷한 다항식
 - 직선의 방정식
      - $f(x_0) + \frac{df(x_0)}{dx}(x-x_0)$
     
 ##### 다변수 함수의 테일러 전개 
  - $f(x_0,y_0) + \frac{\partial f(x_0,y_0)}{\partial x}(x-x_0)+\frac{\partial f(x_0,y_0)}{\partial y}(y-y_0)$

---
### SymPy


```python
import sympy

sympy.init_printing(use_latex='mathjax')
```


```python
x = sympy.symbols('x')
x
```




$\displaystyle x$




```python
f = x * sympy.exp(x)
f
```




$\displaystyle x e^{x}$




```python
# 미분
sympy.diff(f)
```




$\displaystyle x e^{x} + e^{x}$




```python
# 인수분해
sympy.simplify(sympy.diff(f))
```




$\displaystyle \left(x + 1\right) e^{x}$




```python
# 편미분 예제함수

x, y = sympy.symbols('x y')
f = x ** 2 + 4 * x * y + 4 * y ** 2
f
```




$\displaystyle x^{2} + 4 x y + 4 y^{2}$




```python
# 편미분 (미분할 변수를 지정해줘야함)

sympy.diff(f, x)
```




$\displaystyle 2 x + 4 y$




```python
sympy.diff(f, y)
```




$\displaystyle 4 x + 8 y$




```python
# 연쇄법칙

x, mu, sigma = sympy.symbols('x mu sigma')
f = sympy.exp((x-mu) ** 2/sigma**2)
f
```




$\displaystyle e^{\frac{\left(- \mu + x\right)^{2}}{\sigma^{2}}}$




```python
sympy.diff(f, x)
```




$\displaystyle \frac{\left(- 2 \mu + 2 x\right) e^{\frac{\left(- \mu + x\right)^{2}}{\sigma^{2}}}}{\sigma^{2}}$




```python
# 이차도함수
# 미분할 변수를 두 번 넣어주면 된다.

sympy.diff(f, x, x)
```




$\displaystyle \frac{2 \left(1 + \frac{2 \left(\mu - x\right)^{2}}{\sigma^{2}}\right) e^{\frac{\left(\mu - x\right)^{2}}{\sigma^{2}}}}{\sigma^{2}}$



---
#### 예제


```python
x, k, a, b = sympy.symbols('x k a b')  # k,a,b = 상수
```


```python
f = x**3-1
f
```




$\displaystyle x^{3} - 1$




```python
sympy.diff(f)
```




$\displaystyle 3 x^{2}$




```python
f = sympy.log(x**2-3*k)
f
```




$\displaystyle \log{\left(- 3 k + x^{2} \right)}$




```python
sympy.diff(f, x)
```




$\displaystyle \frac{2 x}{- 3 k + x^{2}}$




```python
x, a, b = sympy.symbols('x,a,b')
```


```python
f = sympy.exp(a*x**b)
f
```




$\displaystyle e^{a x^{b}}$




```python
sympy.simplify(sympy.diff(f, x))
```




$\displaystyle a b x^{b - 1} e^{a x^{b}}$



---
#### 연습문제 4.2.6


```python
x, y = sympy.symbols('x y')
```


```python
f = sympy.exp(x**2 + 2*y**2)
f
```




$\displaystyle e^{x^{2} + 2 y^{2}}$




```python
sympy.diff(f, x)
```




$\displaystyle 2 x e^{x^{2} + 2 y^{2}}$




```python
sympy.diff(f, y)
```




$\displaystyle 4 y e^{x^{2} + 2 y^{2}}$




```python
sympy.diff(f, x, x)
```




$\displaystyle 2 \left(2 x^{2} + 1\right) e^{x^{2} + 2 y^{2}}$




```python
sympy.diff(f, x, y)
```




$\displaystyle 8 x y e^{x^{2} + 2 y^{2}}$




```python
sympy.diff(f, y, x)
```




$\displaystyle 8 x y e^{x^{2} + 2 y^{2}}$




```python
sympy.diff(f, y, y)
```




$\displaystyle 4 \left(4 y^{2} + 1\right) e^{x^{2} + 2 y^{2}}$



ea7e2e7ecd3a380195d8fb60af44cdab9ee9c48e
ipynb
Jupyter Notebook
MATH/08_Taylor_Series_Sympy.ipynb
CATERINA-SEUL/Data-Science-School
6189b15a70274d77aa0430efab2d2db81cfe4408
MIT
MATH/08_Taylor_Series_Sympy.ipynb
CATERINA-SEUL/Data-Science-School
6189b15a70274d77aa0430efab2d2db81cfe4408
MIT
MATH/08_Taylor_Series_Sympy.ipynb
CATERINA-SEUL/Data-Science-School
6189b15a70274d77aa0430efab2d2db81cfe4408
MIT
Qwen/Qwen-72B
1. YES
2. YES