## 2019年12月27日金曜日

### 数学 - Python - 解析学 - 多変数の関数 - ベクトル - スカラー積 - 直交、内積、零

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

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

3. $\begin{array}{l}\left(-5,2,7\right)·\left(3,-1,2\right)\\ =-15-2+14\\ \ne 0\end{array}$

4. $\begin{array}{l}\left(\pi ,2,1\right)·\left(2,-\pi ,0\right)\\ =2\pi -2\pi \\ =0\end{array}$

よって、 直交なるのは(b)と (d)。

コード

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

print('4.')

class MyTestCase(TestCase):
def test(self):
a = [(1, -1, 1),
(1, -1, 1),
(-5, 2, 7),
(pi, 2, 1)]
b = [(2, 1, 5),
(2, 3, 1),
(3, -1, 2),
(2, -pi, 0)]
blns = [False, True, False, True]
for a0, b0, bln in zip(a, b, blns):
c = Matrix(a0).dot(Matrix(b0))
if bln:
self.assertEqual(c, 0)
else:
self.assertNotEqual(c, 1)

if __name__ == '__main__':
main()


% ./sample4.py -v
4.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.064s

OK
%