```python
import numpy as np
import scipy as sp
import sklearn as sk

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D

%matplotlib inline
```

    /home/kang/anaconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:279: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
      'Matplotlib is building the font cache using fc-list. '



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


```python
import numpy as np
x = np.linspace(-1, 3, 9)
```




    array([-1. , -0.5,  0. ,  0.5,  1. ,  1.5,  2. ,  2.5,  3. ])




```python
y = f(x)
```


```python
plt.plot(x, y, 'ro')

plt.xlim(-2, 4)
plt.xticks(np.arange(-1, 4))
plt.yticks(np.arange(-5, 4))

plt.show()
```


```python
x = np.linspace(-1, 3, 400, 'ro-')
y = f(x)
plt.plot(x, y)

plt.xlim(-2, 4)
plt.xticks(np.arange(-1, 4))
plt.yticks(np.arange(-5, 4))

plt.show()
```


```python
def get_slope(x, dx) :
    function = x**3 - 3*x**2 + x
    new_function = (x + dx)**3 - 3*(x + dx)**2 + (x +dx)
    
    slope = (new_function - function)/ dx
    return slope
```


```python
get_slope(2, 0.000000000005)
```




    1.000000082740371




```python
get_slope(1.5, 0.000000000005)
```




    -1.2501111257279263




```python
get_slope(-0.5, 0.00000000000005)
```




    4.75175454539567




```python
get_slope(2.5, 0.0000000000005)
```




    4.75175454539567




```python
np.e
```




    2.718281828459045




```python
def f(x, y) :
    return 2* x**2 + 6 * x * y + 7 * y ** 2 - 26 * x - 54 * y + 107
```


```python
xx = np.linspace(-5, 5, 100)
yy = np.linspace(-4, 4, 100)
X , Y = np.meshgrid(xx, yy)
Z = f(X, Y)
```


```python
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
fig.gca(projection='3d').plot_surface(X, Y, Z)
plt.xlabel('x')
plt.ylabel('y')
plt.title("Surface Plot")
plt.show()

```


```python
CS = plt.contour(X, Y, Z, levels = np.arange(0, 300, 20))
plt.clabel(CS, fmt = "%d")
plt.title("Contour Plot")
plt.show()
```

$\frac{\partial f}{\partial x} = 2\,\sqrt{a}\,x$


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


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




$$x$$




```python
type(x)
```




    sympy.core.symbol.Symbol




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




$$x e^{x}$$




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




$$x e^{x} + e^{x}$$




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




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




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




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




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




$$2 x + y$$




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




$$x + 2 y$$




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




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




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




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




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




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




```python
!pip install tangent
```

    Collecting tangent
      Downloading tangent-0.1.9.tar.gz (80kB)
    [K    88% |████████████████████████████▎   | 71kB 677kB/s eta 0:00:01    100% |████████████████████████████████| 81kB 628kB/s 
    [?25hCollecting astor>=0.6 (from tangent)
      Downloading astor-0.6.2-py2.py3-none-any.whl
    Collecting autograd>=1.2 (from tangent)
      Downloading autograd-1.2.tar.gz
    Collecting enum34 (from tangent)
      Downloading enum34-1.1.6-py3-none-any.whl
    Collecting future (from tangent)
      Downloading future-0.16.0.tar.gz (824kB)
    [K    100% |████████████████████████████████| 829kB 577kB/s ta 0:00:01    57% |██████████████████▎             | 471kB 1.7MB/s eta 0:00:01
    [?25hCollecting gast (from tangent)
      Downloading gast-0.2.0.tar.gz
    Requirement already satisfied: nose in /home/kang/anaconda3/lib/python3.6/site-packages (from tangent)
    Requirement already satisfied: numpy in /home/kang/anaconda3/lib/python3.6/site-packages (from tangent)
    Requirement already satisfied: six in /home/kang/anaconda3/lib/python3.6/site-packages (from tangent)
    Collecting tf-nightly>=1.5.0.dev20171026 (from tangent)
      Downloading tf_nightly-1.6.0.dev20180126-cp36-cp36m-manylinux1_x86_64.whl (44.6MB)
    [K    100% |████████████████████████████████| 44.6MB 14kB/s eta 0:00:017  10% |███▍                            | 4.8MB 3.5MB/s eta 0:00:12    11% |███▌                            | 4.9MB 9.1MB/s eta 0:00:05    15% |████▉                           | 6.8MB 2.6MB/s eta 0:00:15    29% |█████████▎                      | 13.0MB 3.0MB/s eta 0:00:11    43% |██████████████                  | 19.4MB 3.4MB/s eta 0:00:08    57% |██████████████████▌             | 25.7MB 3.5MB/s eta 0:00:06    63% |████████████████████▍           | 28.3MB 2.5MB/s eta 0:00:07    80% |█████████████████████████▉      | 36.0MB 2.8MB/s eta 0:00:04    99% |███████████████████████████████▊| 44.2MB 466kB/s eta 0:00:01
    [?25hCollecting protobuf>=3.4.0 (from tf-nightly>=1.5.0.dev20171026->tangent)
      Downloading protobuf-3.5.1-cp36-cp36m-manylinux1_x86_64.whl (6.4MB)
    [K    100% |████████████████████████████████| 6.4MB 100kB/s ta 0:00:011    44% |██████████████▎                 | 2.9MB 219kB/s eta 0:00:17
    [?25hRequirement already satisfied: wheel>=0.26 in /home/kang/anaconda3/lib/python3.6/site-packages (from tf-nightly>=1.5.0.dev20171026->tangent)
    Collecting absl-py>=0.1.6 (from tf-nightly>=1.5.0.dev20171026->tangent)
      Downloading absl-py-0.1.9.tar.gz (79kB)
    [K    100% |████████████████████████████████| 81kB 2.2MB/s ta 0:00:01
    [?25hCollecting tb-nightly<1.6.0a0,>=1.5.0a0 (from tf-nightly>=1.5.0.dev20171026->tangent)
      Downloading tb_nightly-1.5.0a20180126-py3-none-any.whl (3.0MB)
    [K    100% |████████████████████████████████| 3.0MB 211kB/s ta 0:00:011
    [?25hCollecting termcolor>=1.1.0 (from tf-nightly>=1.5.0.dev20171026->tangent)
      Downloading termcolor-1.1.0.tar.gz
    Requirement already satisfied: setuptools in /home/kang/anaconda3/lib/python3.6/site-packages (from protobuf>=3.4.0->tf-nightly>=1.5.0.dev20171026->tangent)
    Collecting bleach==1.5.0 (from tb-nightly<1.6.0a0,>=1.5.0a0->tf-nightly>=1.5.0.dev20171026->tangent)
      Downloading bleach-1.5.0-py2.py3-none-any.whl
    Collecting html5lib==0.9999999 (from tb-nightly<1.6.0a0,>=1.5.0a0->tf-nightly>=1.5.0.dev20171026->tangent)
      Downloading html5lib-0.9999999.tar.gz (889kB)
    [K    100% |████████████████████████████████| 890kB 585kB/s ta 0:00:01
    [?25hCollecting markdown>=2.6.8 (from tb-nightly<1.6.0a0,>=1.5.0a0->tf-nightly>=1.5.0.dev20171026->tangent)
      Downloading Markdown-2.6.11-py2.py3-none-any.whl (78kB)
    [K    100% |████████████████████████████████| 81kB 2.5MB/s ta 0:00:01
    [?25hRequirement already satisfied: werkzeug>=0.11.10 in /home/kang/anaconda3/lib/python3.6/site-packages (from tb-nightly<1.6.0a0,>=1.5.0a0->tf-nightly>=1.5.0.dev20171026->tangent)
    Building wheels for collected packages: tangent, autograd, future, gast, absl-py, termcolor, html5lib
      Running setup.py bdist_wheel for tangent ... [?25ldone
    [?25h  Stored in directory: /home/kang/.cache/pip/wheels/f0/ae/c2/5b094a427f1a1b31c32b94df26678b3efcfe7fedddd2ab4181
      Running setup.py bdist_wheel for autograd ... [?25ldone
    [?25h  Stored in directory: /home/kang/.cache/pip/wheels/ea/d4/2d/e7d74fb5d727853026c54f23fa96f0b8defefc7d57dcaca0aa
      Running setup.py bdist_wheel for future ... [?25ldone
    [?25h  Stored in directory: /home/kang/.cache/pip/wheels/c2/50/7c/0d83b4baac4f63ff7a765bd16390d2ab43c93587fac9d6017a
      Running setup.py bdist_wheel for gast ... [?25ldone
    [?25h  Stored in directory: /home/kang/.cache/pip/wheels/8e/fa/d6/77dd17d18ea23fd7b860e02623d27c1be451521af40dd4a13e
      Running setup.py bdist_wheel for absl-py ... [?25ldone
    [?25h  Stored in directory: /home/kang/.cache/pip/wheels/04/f5/7c/5d4eab10ddf87dec875016e74ba289d87270a90fb2662a76fc
      Running setup.py bdist_wheel for termcolor ... [?25ldone
    [?25h  Stored in directory: /home/kang/.cache/pip/wheels/de/f7/bf/1bcac7bf30549e6a4957382e2ecab04c88e513117207067b03
      Running setup.py bdist_wheel for html5lib ... [?25ldone
    [?25h  Stored in directory: /home/kang/.cache/pip/wheels/6f/85/6c/56b8e1292c6214c4eb73b9dda50f53e8e977bf65989373c962
    Successfully built tangent autograd future gast absl-py termcolor html5lib
    Installing collected packages: astor, future, autograd, enum34, gast, protobuf, absl-py, html5lib, bleach, markdown, tb-nightly, termcolor, tf-nightly, tangent
      Found existing installation: html5lib 0.999999999
        Uninstalling html5lib-0.999999999:
          Successfully uninstalled html5lib-0.999999999
      Found existing installation: bleach 2.0.0
        Uninstalling bleach-2.0.0:
          Successfully uninstalled bleach-2.0.0
    Successfully installed absl-py-0.1.9 astor-0.6.2 autograd-1.2 bleach-1.5.0 enum34-1.1.6 future-0.16.0 gast-0.2.0 html5lib-0.9999999 markdown-2.6.11 protobuf-3.5.1 tangent-0.1.9 tb-nightly-1.5.0a20180126 termcolor-1.1.0 tf-nightly-1.6.0.dev20180126



```python
import tangent

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

import numpy as np
x = np.linspace(-1, 3, 10)

f(x)

fprime0 = tangent.grad(f)

fprime0(1)

fprime = np.vectorize(fprime0)

fprime(x)
```

$$  \int 3x^2 dx $$


$$ \int (3x^2 - 6x + 1)dx $$

$$ \int \left( 2 + 6x + 4\exp(x) + \dfrac{5}{x} \right) dx $$

$$ \int \frac{2x}{x^2 - 1} dx $$ 

$$\int \left( 1 + xy \right) dx  = x + \frac{1}{2}x^2 y  + C(y)$$
$$\int \$$


```python
import numpy as np
import scipy as sp
import sklearn as sk

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pylab as plt
from mpl_toolkits.mplot3d import Axes3D

%matplotlib inline
```

    /home/kang/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:6: UserWarning: 
    This call to matplotlib.use() has no effect because the backend has already
    been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
    or matplotlib.backends is imported for the first time.
    
    The backend was *originally* set to 'module://ipykernel.pylab.backend_inline' by the following code:
      File "/home/kang/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
        "__main__", mod_spec)
      File "/home/kang/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py", line 16, in <module>
        app.launch_new_instance()
      File "/home/kang/anaconda3/lib/python3.6/site-packages/traitlets/config/application.py", line 658, in launch_instance
        app.start()
      File "/home/kang/anaconda3/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 477, in start
        ioloop.IOLoop.instance().start()
      File "/home/kang/anaconda3/lib/python3.6/site-packages/zmq/eventloop/ioloop.py", line 177, in start
        super(ZMQIOLoop, self).start()
      File "/home/kang/anaconda3/lib/python3.6/site-packages/tornado/ioloop.py", line 888, in start
        handler_func(fd_obj, events)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
        return fn(*args, **kwargs)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 440, in _handle_events
        self._handle_recv()
      File "/home/kang/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 472, in _handle_recv
        self._run_callback(callback, msg)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py", line 414, in _run_callback
        callback(*args, **kwargs)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/tornado/stack_context.py", line 277, in null_wrapper
        return fn(*args, **kwargs)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 283, in dispatcher
        return self.dispatch_shell(stream, msg)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 235, in dispatch_shell
        handler(stream, idents, msg)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/ipykernel/kernelbase.py", line 399, in execute_request
        user_expressions, allow_stdin)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/ipykernel/ipkernel.py", line 196, in do_execute
        res = shell.run_cell(code, store_history=store_history, silent=silent)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/ipykernel/zmqshell.py", line 533, in run_cell
        return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2698, in run_cell
        interactivity=interactivity, compiler=compiler, result=result)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2808, in run_ast_nodes
        if self.run_code(code, result):
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-75-5fa60e113fc7>", line 10, in <module>
        get_ipython().magic('matplotlib inline')
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2146, in magic
        return self.run_line_magic(magic_name, magic_arg_s)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2067, in run_line_magic
        result = fn(*args,**kwargs)
      File "<decorator-gen-107>", line 2, in matplotlib
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/magic.py", line 187, in <lambda>
        call = lambda f, *a, **k: f(*a, **k)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/magics/pylab.py", line 99, in matplotlib
        gui, backend = self.shell.enable_matplotlib(args.gui)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2930, in enable_matplotlib
        pt.activate_matplotlib(backend)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/IPython/core/pylabtools.py", line 307, in activate_matplotlib
        matplotlib.pyplot.switch_backend(backend)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 229, in switch_backend
        matplotlib.use(newbackend, warn=False, force=True)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py", line 1305, in use
        reload(sys.modules['matplotlib.backends'])
      File "/home/kang/anaconda3/lib/python3.6/importlib/__init__.py", line 166, in reload
        _bootstrap._exec(spec, module)
      File "/home/kang/anaconda3/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 14, in <module>
        line for line in traceback.format_stack()
    
    
      



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

def f(x) :
    return 3 * x**2 - 6 * x + 1

def f2(x) :
    return 2 + 6 * x + 4 * sympy.exp(x) + (5/x)
```


```python
sp.integrate.quad(f, 0, 1)
```




$$\left ( -1.0, \quad 1.3085085171449517e-14\right )$$




```python
sp.integrate.quad(f2, 1, 10)
```




$$\left ( 88421.50297737827, \quad 1.5276890734473408e-06\right )$$




```python
def f3(x, y) :
    return 1 + x* y
```


```python
sp.integrate.quad(f3, -1, 1)
```


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

```




$$x y + 1$$




```python
#부정 적분
F = sympy.integrate(f, x)
F
```




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




```python
F2 = sympy.integrate(F, y)
F2
```




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




```python
#성환님 답
x, y = sympy.symbols('x y')
f = 1+x*y
F = sympy.integrate(f, x)
F1 = sympy.integrate(F, y)
(F1.subs(x, 1) - F1.subs(x, -1)).evalf()

```




$$2.0 y$$




```python

```

eef8ab75dccff17af63ed10bee459b55318a05ae
ipynb
Jupyter Notebook
Mathmatics/180126, 27.ipynb
KANG91/DSS_lecture_note
dc52aff6870146cc7b7ef0af8fd0a0887bc2734c
MIT
Mathmatics/180126, 27.ipynb
KANG91/DSS_lecture_note
dc52aff6870146cc7b7ef0af8fd0a0887bc2734c
MIT
Mathmatics/180126, 27.ipynb
KANG91/DSS_lecture_note
dc52aff6870146cc7b7ef0af8fd0a0887bc2734c
MIT
Qwen/Qwen-72B
1. YES
2. YES