## 2019年12月24日火曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトル - スカラー積 - それ自身との内積

1. $\begin{array}{l}{\left(2,-1\right)}^{2}\\ =4+1\\ =5\end{array}$

2. $\begin{array}{l}{\left(-1,3\right)}^{2}\\ =1+9\\ =10\end{array}$

3. $\begin{array}{l}{\left(2,-1,5\right)}^{2}\\ =4+1+25\\ =30\end{array}$

4. $\begin{array}{l}{\left(-1,-2,3\right)}^{2}\\ =1+4+9\\ =14\end{array}$

5. $\begin{array}{l}\left(\pi ,3,-1\right)\\ ={\pi }^{2}+10\end{array}$

6. $\begin{array}{l}{\left(15,-2,4\right)}^{2}\\ =225+4+16\\ =245\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, pi, Matrix

print('1.')

a = [(2, -1),
(-1, 3),
(2, -1, 5),
(-1, -2, 3),
(pi, 3, -1),
(15, -2, 4)]

class MyTestCase(TestCase):
def test(self):
spam = [5, 10, 30, 14, pi ** 2 + 10, 245]
for s, t in zip(a, spam):
A = Matrix(s)
self.assertEqual(A.dot(A), t)

if __name__ == '__main__':
main()

% ./sample1.py -v
1.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.040s

OK
%