## 2020年4月10日金曜日

### 数学 - Python - 解析学 - 多変数の関数 - 多変数の関数 - 微分可能性と勾配 - n次元、内積、偏微分、座標

1. $\begin{array}{l}A=\left({a}_{1},\dots ,{a}_{n}\right)\\ X=\left({x}_{1},\dots ,{x}_{n}\right)\in {\text{ℝ}}^{n}\end{array}$

とおく。
このとき、 内積、偏微分、座標による表現について、

$\begin{array}{l}f\left(X\right)\\ =A·X\\ =\sum _{k=1}^{n}{a}_{k}{x}_{k}\\ \frac{\partial f}{\partial {x}_{k}}={a}_{k}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
import random
from sympy import symbols, Derivative, Matrix, solve
from sympy.plotting import plot3d, plot3d_parametric_line

print('4.')

aks = symbols('a:10')
A = Matrix(aks)
xs = symbols('x:10')
X = Matrix(xs)
f = A.dot(X)

class TestPartialDerivative(TestCase):
def test_xs(self):
for ak, xk in zip(aks, xs):
self.assertEqual(Derivative(f, xk, 1).doit(), ak)

a, b = [random.randrange(-5, 6) for _ in range(2)]
x, y = symbols('x, y')
p = plot3d(a * x + b * y,
show=False)

p.show()
p.save('sample4.png')

if __name__ == "__main__":
main()


% ./sample4.py -v
4.
test_xs (__main__.TestPartialDerivative) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.010s

OK
%