## 2020年4月24日金曜日

### 数学 - Python - 解析学 - 多変数の関数 - 合成微分律と勾配ベクトル - 1変数の関数、ノルム、1変数の微分可能な関数、2変数の微分可能な関数

1. $\begin{array}{l}r\\ =∥X∥\\ =∥\left(x,y,z\right)∥\\ =\sqrt{{x}^{2}+{y}^{2}+{z}^{2}}\\ \frac{df}{\mathrm{dx}}\\ =\frac{\partial g}{\partial x}\\ =\frac{\mathrm{dg}}{dr}\frac{x}{\sqrt{{x}^{2}+{y}^{2}+{z}^{2}}}\\ \frac{df}{\mathrm{dy}}=\frac{df}{dr}\frac{y}{\sqrt{{x}^{2}+{y}^{2}+{z}^{2}}}\\ \frac{df}{\mathrm{dz}}=\frac{df}{dr}\frac{z}{\sqrt{{x}^{2}+{y}^{2}+{z}^{2}}}\\ {\left(\frac{df}{\mathrm{dx}}\right)}^{2}+{\left(\frac{df}{\mathrm{dy}}\right)}^{2}+{\left(\frac{df}{\mathrm{dz}}\right)}^{2}\\ ={\left(\frac{df}{dr}\right)}^{2}\frac{{x}^{2}+{y}^{2}+{z}^{2}}{{x}^{2}+{y}^{2}+{z}^{2}}\\ ={\left(\frac{df}{dr}\right)}^{2}\\ ={\left(\frac{dg}{dr}\right)}^{2}\end{array}$

2. $\begin{array}{l}\frac{\partial g}{\partial x}\\ =\frac{\partial f}{\partial x}\\ =\left(\frac{\partial f}{\partial u},\frac{\partial f}{\partial v}\right)·\left(1,1\right)\\ =\frac{\partial f}{\partial u}+\frac{\partial f}{\partial v}\\ \frac{\partial g}{\partial y}\\ =\left(\frac{\partial f}{\partial u},\frac{\partial f}{\partial v}\right)·\left(1,-1\right)\\ =\frac{\partial f}{\partial u}-\frac{\partial f}{\partial v}\\ \frac{\partial g}{\partial x}\frac{\partial g}{\partial y}\\ ={\left(\frac{\partial f}{\partial u}\right)}^{2}-{\left(\frac{\partial f}{\partial v}\right)}^{2}\end{array}$

3. $t=2x+7y$

とおく。

このとき、

$\begin{array}{l}\frac{\partial g}{\partial x}\\ =\frac{\partial f}{\partial x}\\ =\frac{df}{ds}2\\ \frac{\partial g}{\partial y}=\frac{df}{ds}7\end{array}$

よって、

$\begin{array}{l}\frac{1}{2}\frac{\partial g}{\partial x}=\frac{1}{7}\frac{\partial g}{\partial y}\\ 2\frac{\partial g}{\partial y}=7\frac{\partial g}{\partial x}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Function, Matrix
from sympy.plotting import plot3d

print('8.')

x, y, z, r, u, v = symbols('x, y, z, r, u, v', real=True)

class TestDerivativeChainRule(TestCase):
def test_a(self):
X = Matrix([x, y, z])
d = {r: X.norm()}
g = Function('g')(r)
f = g.subs(d)
self.assertEqual(
(g.diff(r, 1).subs(d) ** 2).simplify(),
(f.diff(x, 1) ** 2 + f.diff(y, 1) ** 2 + f.diff(z, 1) ** 2)
.simplify()
)

def test_b(self):
f = Function('f')(u, v)
d = {u: x + y, v: x - y}
g = f.subs(d)
self.assertEqual(
(g.diff(x, 1) * g.diff(y, 1)).simplify(),
(f.diff(u) ** 2 - f.diff(v, 1) ** 2).subs(d).simplify()
)

def test_c(self):
f = Function('f')(r)
d = {r: 2 * x + 7 * y}
g = f.subs(d)
self.assertEqual(2 * g.diff(y), 7 * g.diff(x, 1))

if __name__ == "__main__":
main()


% ./sample8.py -v
8.
test_a (__main__.TestDerivativeChainRule) ... ok
test_b (__main__.TestDerivativeChainRule) ... ok
test_c (__main__.TestDerivativeChainRule) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.608s

OK
%