## 2020年7月14日火曜日

### 数学 - Python - 解析学 - ベクトル - ベクトル積 - 2つのベクトルによって張られる平行四辺形の面積、ノルム

1. $\parallel A×B\parallel$
$=\parallel \left(3,-2,4\right)×\left(5,1,1\right)\parallel$
$=\parallel \left(-2-4,20-3,3+10\right)\parallel$
$=\parallel \left(-6,17,13\right)\parallel$
$=\sqrt{36+289+169}$
$=\sqrt{494}$

2. $\parallel \left(0,-14,7\right)\parallel =\sqrt{196+49}=\sqrt{245}=7\sqrt{5}$

3. $\parallel \left(-3,19,10\right)\parallel =\sqrt{9+361+100}=\sqrt{470}$

4. $\parallel \left(13,14,4\right)\parallel =\sqrt{169+196+16}=\sqrt{381}$

コード

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

print('9.')

def eq(x, y):
return all([x0.expand() == y0.expand() for x0, y0 in zip(x, y)])

class Test(TestCase):
def test(self):
ts = [((3, -2, 4), (5, 1, 1)),
((3, 1, 2), (-1, 2, 4)),
((4, -2, 5), (3, 1, -1)),
((-2, 1, 3), (2, -3, 4))]
ss = [sqrt(494), 7 * sqrt(5), sqrt(470), sqrt(381)]
for i, ((a, b), s) in enumerate(zip(ts, ss)):
print(f'({chr(ord("a") + i)})')
self.assertEqual(Matrix(a).cross(Matrix(b)).norm(), s)

if __name__ == "__main__":
main()


% ./sample9.py -v
9.
test (__main__.Test) ... (a)
(b)
(c)
(d)
ok

----------------------------------------------------------------------
Ran 1 test in 0.077s

OK
%