## 2020年7月1日水曜日

### 数学 - Pytyhon - 解析学 - ベクトル - 平面 - 2平面のなす角の余弦

1. $\mathrm{cos}\theta =\frac{1-1-1}{\sqrt{3}\sqrt{3}}=-\frac{1}{3}$

2. $\mathrm{cos}\theta =\frac{-2}{\sqrt{14}\sqrt{3}}=-\frac{2}{\sqrt{42}}=-\frac{\sqrt{42}}{21}$

3. $\mathrm{cos}\theta =\frac{4}{\sqrt{6}\sqrt{11}}=\frac{4}{\sqrt{66}}=\frac{2\sqrt{66}}{33}$

4. $\mathrm{cos}\theta =\frac{-2}{\sqrt{6}\sqrt{3}}=-\frac{2}{3\sqrt{2}}=-\frac{\sqrt{2}}{3}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import sqrt, Rational, Matrix

print('15.')

class TestCosin(TestCase):
def test(self):
ts = [((1, 1, 1), (1, -1, -1)),
((2, 3, -1), (1, -1, 1)),
((1, 2, -1), (-1, 3, 1)),
((2, 1, 1), (-1, -1, 1))]
cs = [-Rational(1, 3),
-sqrt(42) / 21,
2 * sqrt(66) / 33,
-sqrt(2) / 3]
for i, (t, c) in enumerate(zip(ts, cs)):
print(f'({chr(ord("a") + i)})')
a, b = [Matrix(s) for s in t]
self.assertEqual(a.dot(b) / (a.norm() * b.norm()), c)

if __name__ == "__main__":
main()


% ./sample15.py -v
15.
test (__main__.TestCosin) ... (a)
(b)
(c)
(d)
ok

----------------------------------------------------------------------
Ran 1 test in 0.038s

OK
%