```python
def f(x):
    return x**3 -3*x**2 + x
```


```python
from scipy.misc import derivative

print(derivative(f, 0, dx=1e-6))
print(derivative(f, 1, dx=1e-6))
```

    1.000000000001
    -2.000000000002



```python
def relu(x):
    return np.where(x>0, x, 0)

xx = np.linspace(-2, 2, 100)
plt.plot(xx, relu(xx))
plt.plot(0, 0, marker="o", ms=10)
plt.title("ReLu")
plt.xlabel("$x$")
plt.ylabel("ReLU(x)")
plt.show()
```


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


```


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




$\displaystyle x$




```python
type(x)
```




    sympy.core.symbol.Symbol




```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.simplify(sympy.diff(f,x))
```




$\displaystyle \frac{2 \left(- \mu + 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
f = x**3 - 1
```


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




$\displaystyle 3 x^{2}$




```python
k = sympy.symbols('k')
f = sympy.log(x**2- 3*k)
sympy.simplify(sympy.diff(f, x))
```




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




```python
a,b = sympy.symbols('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}}$




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


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

fx = sympy.simplify(sympy.diff(f, x))
fy = sympy.simplify(sympy.diff(f, y))
fxx = sympy.simplify(sympy.diff(f, x, x))
fxy = sympy.simplify(sympy.diff(f, x, y))
fyx = sympy.simplify(sympy.diff(f, y, x))
fyy = sympy.simplify(sympy.diff(f, y, y))


```

    2*x*exp(x**2 + 2*y**2) 4*y*exp(x**2 + 2*y**2) (4*x**2 + 2)*exp(x**2 + 2*y**2) 8*x*y*exp(x**2 + 2*y**2) 8*x*y*exp(x**2 + 2*y**2) (16*y**2 + 4)*exp(x**2 + 2*y**2)



```python
fx, fy, fxx, fxy, fyx, fyy
```




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




```python
x = sympy.symbols('x')
f = x*sympy.exp(x) + sympy.exp(x)
f
```




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




```python
sympy.integrate(f)
```




$\displaystyle x e^{x}$




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




$\displaystyle 2 x + y$




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




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




```python
f = 3*(x**2)
sympy.integrate(f)
```




$\displaystyle x^{3}$




```python
f = 3*(x**2) - 6*x + 1
```


```python
sympy.integrate(f)
```




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




```python
f = 2 + 6*x + 4*(sympy.exp(x)) + 5*(x**-1)
```


```python
f
```




$\displaystyle 6 x + 4 e^{x} + 2 + \frac{5}{x}$




```python
sympy.integrate(f)
```




$\displaystyle 3 x^{2} + 2 x + 4 e^{x} + 5 \log{\left(x \right)}$




```python
f = 2*x/x**2 -1
```


```python
sympy.integrate(f)
```




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




```python
g = 1+(x*y)
g
```




$\displaystyle x y + 1$




```python
sympy.integrate(g, x)
```




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




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


```python
sympy.integrate(g, x)
```




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




```python
f = x**3 - 3*x**2 + x + 6
```


```python
F = sympy.integrate(f)
```


```python
(F.subs(x, 2) - F.subs(x, 0)).evalf()
```




$\displaystyle 10.0$




```python
import scipy as sp
def f(x):
    return x**3 - 3*x**2 + x + 6

sp.integrate.quad(f, 0, 2)
    
```




$\displaystyle \left( 10.0, \  1.1102230246251565e-13\right)$




```python
import scipy as sp
def f(x, y):
    return np.exp(-x * y) / y**2

sp.integrate.dblquad(f, 1, np.inf, lambda x:0, lambda x:np.inf)
```




$\displaystyle \left( 0.4999999999999961, \  1.068453874338024e-08\right)$




```python
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
_x = np.arange(12) / 2 + 2
_y = np.arange(12) / 2
X, Y = np.meshgrid(_x, _y)
x, y = X.ravel(), Y.ravel()
z = x * x - 10 * x + y + 50
z0 = np.zeros_like(z)
ax.bar3d(x, y, z0, 0.48, 0.48, z)
ax.set_xlim(0, 10)
ax.set_ylim(-2, 10)
ax.set_zlim(0, 50)
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.title("f(x, y)")
plt.show()

```


```python
from mpl_toolkits.mplot3d import Axes3D
```


```python
#연습문제 4.3.6
def f(x, y):
    return (1+x*y)
sp.integrate.dblquad(f, -1, 1, lambda x:-1, lambda x:1 )
```




$\displaystyle \left( 4.0, \  4.440892098500626e-14\right)$




```python

```

2a44a98850cabc67a8b7fea832330b3381aad0d4
ipynb
Jupyter Notebook
200131_mathsympy.ipynb
BAEintelli/TIL
ef18333837198b5bb7d5add66f6b1a96d3b01844
MIT
200131_mathsympy.ipynb
BAEintelli/TIL
ef18333837198b5bb7d5add66f6b1a96d3b01844
MIT
200131_mathsympy.ipynb
BAEintelli/TIL
ef18333837198b5bb7d5add66f6b1a96d3b01844
MIT
Qwen/Qwen-72B
1. YES
2. YES