## 2018年2月15日木曜日

### 数学 - Python - 解析学 - 多変数の関数 - 高次偏導関数、テイラーの定理(偏微分、グラディエント(gradient)、三角関数(正弦、余弦)、累乗(平方)、等式)

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

よって、

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

コード(Emacs)

Python 3

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

r, a, b = symbols('r, a, b', nonzero=True)
x = r * sin(a) * cos(b)
y = r * sin(a) * sin(b)
z = r * cos(b)
g = Function('g')(r, a, b)
expr = Derivative(g, r, 1) ** 2 + (1 / r * Derivative(g, a, 1)
) ** 2 + (1 / (r * sin(a)) * Derivative(g, b, 1)) ** 2
for t in [expr, expr.doit()]:
pprint(t)
print()


$./sample11.py 2 2 ⎛∂ ⎞ ⎛∂ ⎞ 2 ⎜──(g(r, a, b))⎟ ⎜──(g(r, a, b))⎟ ⎛∂ ⎞ ⎝∂a ⎠ ⎝∂b ⎠ ⎜──(g(r, a, b))⎟ + ───────────────── + ───────────────── ⎝∂r ⎠ 2 2 2 r r ⋅sin (a) 2 2 ⎛∂ ⎞ ⎛∂ ⎞ 2 ⎜──(g(r, a, b))⎟ ⎜──(g(r, a, b))⎟ ⎛∂ ⎞ ⎝∂a ⎠ ⎝∂b ⎠ ⎜──(g(r, a, b))⎟ + ───────────────── + ───────────────── ⎝∂r ⎠ 2 2 2 r r ⋅sin (a)$