## 2020年5月3日日曜日

### 数学 - Python - 立体的な広がりの中の図形 - 空間図形 - 空間のベクトル - 座標軸とベクトル - ベクトルの大きさ、距離の公式

1. $\begin{array}{l}\left|\left(-6,3,2\right)\right|\\ =\sqrt{36+9+4}\\ =7\end{array}$

2. $\begin{array}{l}\left|\left(2-\sqrt{3},2+\sqrt{3},6\right)\right|\\ =\sqrt{{\left(2-\sqrt{3}\right)}^{2}+{\left(2+\sqrt{3}\right)}^{2}+36}\\ =\sqrt{8+6+36}\\ =5\sqrt{2}\end{array}$

コード

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

print('8.')

a = Matrix([-6, 3, 2])
b = Matrix([2 - sqrt(3), 2 + sqrt(3), 6])

class TestVectorNorm(TestCase):
def test1(self):
self.assertEqual(a.norm().simplify(), 7)

def test2(self):
self.assertEqual(b.norm().simplify(), 5 * sqrt(2))

t = symbols('t')
p = plot3d_parametric_line(*[(*(t * v), (t, 0, 1)) for v in [a, b]],
xlim=(-10, 10),
ylim=(-10, 10),
legend=True,
show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
o.line_color = color
p.show()
p.save('sample8.png')

if __name__ == "__main__":
main()


% ./sample8.py -v
8.
test1 (__main__.TestVectorNorm) ... ok
test2 (__main__.TestVectorNorm) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.265s

OK
%