## 2018年2月5日月曜日

### 数学 - Python - 解析学 - 多変数の関数 - 高次偏導関数、テイラーの定理(三角関数(正弦、余弦)、極座標、グラディエント(gradient)、内積(ドット積、スカラー積))

1. $\begin{array}{}\frac{\partial g}{\partial r}\\ =gradf\left(x,y\right).\left(\mathrm{cos}\theta ,\mathrm{sin}\theta \right)\\ =\frac{\partial f}{\partial x}\mathrm{cos}\theta +\frac{\partial f}{\partial y}\mathrm{sin}\theta \end{array}$
$\begin{array}{}\frac{{\partial }^{2}g}{\partial {r}^{2}}\\ =\left(\frac{{\partial }^{2}f}{\partial {x}^{2}}\mathrm{cos}\theta +\frac{{\partial }^{2}f}{\partial x\partial y}\mathrm{sin}\theta ,\frac{{\partial }^{2}f}{\partial y\partial x}\mathrm{cos}\theta +\frac{{\partial }^{2}f}{\partial {y}^{2}}\mathrm{sin}\theta \right)·\left(\mathrm{cos}\theta ,\mathrm{sin}\theta \right)\\ =\frac{{\partial }^{2}f}{\partial {x}^{2}}{\mathrm{cos}}^{2}\theta +2\frac{{\partial }^{2}f}{\partial x\partial y}\mathrm{sin}\theta \mathrm{cos}\theta +\frac{{\partial }^{2}f}{\partial {y}^{2}}{\mathrm{sin}}^{2}\theta \end{array}$
$\begin{array}{}\frac{\partial g}{\partial \theta }\\ =\left(\frac{\partial f}{\partial x},\frac{\partial f}{\partial y}\right)·\left(-r\mathrm{sin}\theta ,r\mathrm{cos}\theta \right)\\ =-\frac{\partial f}{\partial x}r\mathrm{sin}\theta +\frac{\partial f}{\partial y}r\mathrm{cos}\theta \end{array}$
$\begin{array}{}\frac{{\partial }^{2}g}{\partial {\theta }^{2}}\\ =-\left(\frac{{\partial }^{2}f}{\partial {x}^{2}},\frac{{\partial }^{2}f}{\partial y\partial x}\right)·\left(-r\mathrm{sin}\theta ,r\mathrm{cos}\theta \right)·r\mathrm{sin}\theta -\frac{\partial f}{\partial x}r\mathrm{cos}\theta \\ +\left(\frac{{\partial }^{2}f}{\partial x\partial y},\frac{{\partial }^{2}f}{\partial {y}^{2}}\right)·\left(-r\mathrm{sin}\theta ,r\mathrm{cos}\theta \right)·r\mathrm{cos}\theta -\frac{\partial f}{\partial y}r\mathrm{sin}\theta \\ =\frac{{\partial }^{2}f}{\partial {x}^{2}}{r}^{2}{\mathrm{sin}}^{2}\theta -\frac{{\partial }^{2}f}{\partial x\partial y}{r}^{2}\mathrm{sin}\theta \mathrm{cos}\theta -\frac{\partial f}{\partial x}r\mathrm{cos}\theta \\ -\frac{{\partial }^{2}f}{\partial x\partial y}{r}^{2}\mathrm{sin}\theta \mathrm{cos}\theta +\frac{{\partial }^{2}f}{\partial {y}^{2}}{r}^{2}{\mathrm{cos}}^{2}\theta -\frac{\partial f}{\partial y}r\mathrm{sin}\theta \\ =\frac{{\partial }^{2}f}{\partial {x}^{2}}{r}^{2}{\mathrm{sin}}^{2}\theta -2\frac{{\partial }^{2}f}{\partial x\partial y}{r}^{2}\mathrm{sin}\theta \mathrm{cos}\theta +\frac{{\partial }^{2}f}{\partial {y}^{2}}{r}^{2}{\mathrm{cos}}^{2}\theta -\frac{\partial f}{\partial x}r\mathrm{cos}\theta \\ -\frac{\partial f}{\partial y}r\mathrm{sin}\theta \end{array}$

よって、

$\begin{array}{}\frac{{\partial }^{2}g}{\partial {r}^{2}}+\frac{1}{r}\frac{\partial g}{\partial r}+\frac{1}{{r}^{2}}\frac{{\partial }^{2}g}{\partial {\theta }^{2}}\\ =\frac{{\partial }^{2}f}{\partial {x}^{2}}\left({\mathrm{cos}}^{2}\theta +{\mathrm{sin}}^{2}\theta \right)+\frac{{\partial }^{2}f}{\partial {y}^{2}}\left({\mathrm{sin}}^{2}\theta +{\mathrm{cos}}^{2}\theta \right)\\ +\frac{{\partial }^{2}f}{\partial x\partial y}\left(2\mathrm{sin}\theta \mathrm{cos}\theta -2\mathrm{sin}\theta \mathrm{cos}\theta \right)\\ +\frac{\partial f}{\partial x}\left(\frac{1}{r}\mathrm{cos}\theta -\frac{1}{r}\mathrm{cos}\theta \right)+\frac{\partial f}{\partial y}\left(\frac{1}{r}\mathrm{sin}\theta -\frac{1}{r}\mathrm{sin}\theta \right)\\ =\frac{{\partial }^{2}f}{\partial {x}^{2}}+\frac{{\partial }^{2}f}{\partial {y}^{2}}\end{array}$

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, sin, cos, Function, Derivative

r, θ = symbols('r, θ', real=True)
x = r * sin(θ)
y = r * cos(θ)
f = Function('f')(x, y)
Df = Derivative(f, r, 2) + 1 / r * Derivative(f, r, 1) + \
1 / (r ** 2) * Derivative(f, r, 2)

for t in [Df, Df.doit(), Df.doit().factor()]:
pprint(t.factor())
print()


$./sample4.py 2 2 2 ∂ ∂ ∂ r ⋅───(f(r⋅sin(θ), r⋅cos(θ))) + r⋅──(f(r⋅sin(θ), r⋅cos(θ))) + ───(f(r⋅sin(θ), 2 ∂r 2 ∂r ∂r ────────────────────────────────────────────────────────────────────────────── 2 r r⋅cos(θ))) ────────── ⎛ 2 ⎞│ ⎛⎛ 2 2 2 ⎜ ∂ ⎟│ 2 ⎜⎜ ∂ r ⋅sin (θ)⋅⎜────(f(ξ₁, r⋅cos(θ)))⎟│ + 2⋅r ⋅sin(θ)⋅cos(θ)⋅⎜⎜───────( ⎜ 2 ⎟│ ⎝⎝∂ξ₂ ∂ξ₁ ⎝∂ξ₁ ⎠│ξ₁=r⋅sin(θ) ────────────────────────────────────────────────────────────────────────────── ⎞│ ⎞│ ⎛ 2 ⎞│ ⎟│ ⎟│ 2 2 ⎜ ∂ ⎟│ f(ξ₁, ξ₂))⎟│ ⎟│ + r ⋅cos (θ)⋅⎜────(f(r⋅sin(θ), ξ₂))⎟│ ⎠│ξ₁=r⋅sin(θ)⎠│ξ₂=r⋅cos(θ) ⎜ 2 ⎟│ ⎝∂ξ₂ ⎠│ξ₂=r ────────────────────────────────────────────────────────────────────────────── ⎛ ∂ ⎞│ ⎛ ∂ + r⋅sin(θ)⋅⎜───(f(ξ₁, r⋅cos(θ)))⎟│ + r⋅cos(θ)⋅⎜───(f(r⋅sin( ⎝∂ξ₁ ⎠│ξ₁=r⋅sin(θ) ⎝∂ξ₂ ⋅cos(θ) ────────────────────────────────────────────────────────────────────────────── 2 r ⎛ 2 ⎞│ ⎞│ 2 ⎜ ∂ ⎟│ θ), ξ₂))⎟│ + sin (θ)⋅⎜────(f(ξ₁, r⋅cos(θ)))⎟│ + 2⋅sin(θ) ⎠│ξ₂=r⋅cos(θ) ⎜ 2 ⎟│ ⎝∂ξ₁ ⎠│ξ₁=r⋅sin(θ) ────────────────────────────────────────────────────────────────────────────── ⎛⎛ 2 ⎞│ ⎞│ ⎛ 2 ⎜⎜ ∂ ⎟│ ⎟│ 2 ⎜ ∂ ⋅cos(θ)⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ ⎟│ + cos (θ)⋅⎜────(f(r⋅sin ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₁=r⋅sin(θ)⎠│ξ₂=r⋅cos(θ) ⎜ 2 ⎝∂ξ₂ ────────────────────────────────────────────────────────────────────────────── ⎞│ ⎟│ (θ), ξ₂))⎟│ ⎟│ ⎠│ξ₂=r⋅cos(θ) ────────────────────── ⎛ 2 ⎞│ ⎛⎛ 2 2 2 ⎜ ∂ ⎟│ 2 ⎜⎜ ∂ r ⋅sin (θ)⋅⎜────(f(ξ₁, r⋅cos(θ)))⎟│ + 2⋅r ⋅sin(θ)⋅cos(θ)⋅⎜⎜───────( ⎜ 2 ⎟│ ⎝⎝∂ξ₂ ∂ξ₁ ⎝∂ξ₁ ⎠│ξ₁=r⋅sin(θ) ────────────────────────────────────────────────────────────────────────────── ⎞│ ⎞│ ⎛ 2 ⎞│ ⎟│ ⎟│ 2 2 ⎜ ∂ ⎟│ f(ξ₁, ξ₂))⎟│ ⎟│ + r ⋅cos (θ)⋅⎜────(f(r⋅sin(θ), ξ₂))⎟│ ⎠│ξ₁=r⋅sin(θ)⎠│ξ₂=r⋅cos(θ) ⎜ 2 ⎟│ ⎝∂ξ₂ ⎠│ξ₂=r ────────────────────────────────────────────────────────────────────────────── ⎛ ∂ ⎞│ ⎛ ∂ + r⋅sin(θ)⋅⎜───(f(ξ₁, r⋅cos(θ)))⎟│ + r⋅cos(θ)⋅⎜───(f(r⋅sin( ⎝∂ξ₁ ⎠│ξ₁=r⋅sin(θ) ⎝∂ξ₂ ⋅cos(θ) ────────────────────────────────────────────────────────────────────────────── 2 r ⎛ 2 ⎞│ ⎞│ 2 ⎜ ∂ ⎟│ θ), ξ₂))⎟│ + sin (θ)⋅⎜────(f(ξ₁, r⋅cos(θ)))⎟│ + 2⋅sin(θ) ⎠│ξ₂=r⋅cos(θ) ⎜ 2 ⎟│ ⎝∂ξ₁ ⎠│ξ₁=r⋅sin(θ) ────────────────────────────────────────────────────────────────────────────── ⎛⎛ 2 ⎞│ ⎞│ ⎛ 2 ⎜⎜ ∂ ⎟│ ⎟│ 2 ⎜ ∂ ⋅cos(θ)⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ ⎟│ + cos (θ)⋅⎜────(f(r⋅sin ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₁=r⋅sin(θ)⎠│ξ₂=r⋅cos(θ) ⎜ 2 ⎝∂ξ₂ ────────────────────────────────────────────────────────────────────────────── ⎞│ ⎟│ (θ), ξ₂))⎟│ ⎟│ ⎠│ξ₂=r⋅cos(θ) ──────────────────────$