## 2019年2月5日火曜日

### 本 - ブルーバックス( @bluebacks_pub ) - 飽本一裕著 - 今日から使える微分方程式 普及版 例題で身につく理系の必須テクニック - 微分の定義

1. $\begin{array}{}\frac{df\left(x\right)}{\mathrm{dx}}\\ =\underset{\Delta x\to 0}{\mathrm{lim}}\frac{f\left(x+\Delta x\right)-f\left(x\right)}{\Delta x}\\ =\underset{\Delta x\to 0}{\mathrm{lim}}\frac{{\left(x+\Delta x\right)}^{2}-{x}^{2}}{\Delta x}\\ =\underset{\Delta x\to 0}{\mathrm{lim}}\frac{{x}^{2}+2\left(\Delta x\right)x+{\left(\Delta x\right)}^{2}-{x}^{2}}{\Delta x}\\ =\underset{\Delta x\to 0}{\mathrm{lim}}\left(2x-\left(\Delta x\right)\right)\\ =2x\end{array}$

2. $\begin{array}{}\frac{df\left(x\right)}{\mathrm{dx}}\\ =\underset{\Delta x\to 0}{\mathrm{lim}}\frac{\mathrm{cos}\left(x+\Delta x\right)-\mathrm{cos}x}{\Delta x}\\ =\underset{\Delta x\to 0}{\mathrm{lim}}\frac{\mathrm{cos}x\mathrm{cos}\left(\Delta x\right)-\mathrm{sin}x\mathrm{sin}\left(\Delta x\right)-\mathrm{cos}x}{\Delta x}\\ =\underset{\Delta x\to 0}{\mathrm{lim}}\frac{\mathrm{cos}x\left(\mathrm{cos}\left(\Delta x\right)-1\right)-\mathrm{sin}x\mathrm{sin}\left(\Delta x\right)}{\Delta x}\\ =-\mathrm{sin}x\end{array}$

コード

Python 3

```#!/usr/bin/env python3
from sympy import pprint, symbols, Derivative, cos, plot

x, dx = symbols('x, △x')

def d(f):
return ((f.subs({x: x + dx}) - f) / dx).limit(dx, 0)

fs = [x ** 2, cos(x)]

for i, f in enumerate(fs, 1):
print(f'({i})')
l = Derivative(f, x, 1).doit()
for t in [d(f), l]:
pprint(t)
print()
print()

p = plot(*fs, ylim=(-10, 10), legend=True, show=False)

colors = ['red', 'green']
for i, color in enumerate(colors):
p[i].line_color = color

p.save('sample1.png')
```

```\$ python3 sample1.py
(1)
2⋅x

2⋅x

(2)
-sin(x)

-sin(x)

\$
```