## 2020年5月16日土曜日

### 数学 - Pytyhon - 解析学 - 多変数の関数 - 合成微分律と勾配ベクトル - 方向微分係数 - 最も急速に増加する向き、ノルム、累乗、有理数

1. $\begin{array}{l}\frac{x}{{∥X∥}^{\frac{3}{2}}}\\ =\frac{x}{{\left({x}^{2}+{y}^{2}+{z}^{2}\right)}^{\frac{3}{4}}}\\ gradf\left(X\right)\\ =\frac{1}{{\left({x}^{2}+{y}^{2}+{z}^{2}\right)}^{\frac{3}{2}}}\\ \left({\left({x}^{2}+{y}^{2}+{z}^{2}\right)}^{\frac{3}{4}}-x·\frac{3}{4}{\left({x}^{2}+{y}^{2}+{z}^{2}\right)}^{-\frac{1}{4}}·2x,\\ -x·\frac{3}{4}{\left({x}^{2}+{y}^{2}+{z}^{2}\right)}^{-\frac{1}{4}}·2y,\\ -x·\frac{3}{4}{\left({x}^{2}+{y}^{2}+{z}^{2}\right)}^{-\frac{1}{4}}·2z\right)\end{array}$

よって、問題 の X の関数が与えられた点（1，-1，2）で最も急速に増加する向きは、

$\begin{array}{l}·\\ \frac{1}{{6}^{\frac{3}{2}}}\left({6}^{\frac{3}{4}}-\frac{3}{2}·{6}^{-\frac{1}{4}},\frac{3}{2}·{6}^{-\frac{1}{4}},-\frac{3}{2}·{6}^{-\frac{1}{4}}·2\right)\\ =\left(\frac{1}{{6}^{\frac{3}{4}}}-\frac{3}{2·{6}^{\frac{7}{4}}},\frac{3}{2·{6}^{\frac{7}{4}}},-\frac{3}{{6}^{\frac{7}{4}}}\right)\\ =\left(\frac{3}{4·{6}^{\frac{3}{4}}},\frac{3}{2·{6}^{\frac{7}{4}}},-\frac{3}{{6}^{\frac{7}{4}}}\right)\end{array}$

2. $\begin{array}{l}{∥X∥}^{5}={\left({x}^{2}+{y}^{2}+{z}^{2}+{w}^{2}\right)}^{\frac{5}{2}}\\ grad{∥X∥}^{5}\\ =5{\left({x}^{2}+{y}^{2}+{z}^{2}+{w}^{2}\right)}^{\frac{3}{2}}\left(x,y,z,w\right)\\ 5{\left(1+4+1+1\right)}^{\frac{3}{2}}\left(1,2,-1,1\right)\\ =5·{7}^{\frac{3}{2}}\left(1,2,-1,1\right)\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, sin, cos, Rational, sqrt, pi
from sympy.plotting import plot3d

print('4.')

x, y, z, w = symbols('x, y, z, w', real=True)

def test_a(self):
f = x / Matrix([x, y, z]).norm() ** Rational(3, 2)

self.assertEqual(
Matrix([f.diff(o, 1) for o in [x, y, z]]).subs(
{x: 1, y: -1, z: 2}),
3 * Matrix([1 / (4 * 6 ** Rational(3, 4)),
1 / (2 * 6 ** Rational(7, 4)),
-1 / 6 ** Rational(7, 4)])
)

def test_b(self):
f = Matrix([x, y, z, w]).norm() ** 5
self.assertEqual(
Matrix([f.diff(o, 1) for o in [x, y, z, w]]).subs(
{x: 1, y: 2, z: -1, w: 1}),
5 * 7 ** Rational(3, 2) * Matrix([1, 2, -1, 1])
)

for i, f in enumerate([x / Matrix([x, y, 2]).norm() ** Rational(3, 2),
Matrix([x, y, -1, 1]).norm() ** 5]):
c = chr(ord("a") + i)
p = plot3d(f,
(x, -5, 5),
(y, -5, 5),
show=False)
p.save(f'sample4_{c}.png')
p.show()

if __name__ == "__main__":
main()


% ./sample4.py -v
4.