2020年5月3日日曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第11章(立体的な広がりの中の図形 - 空間図形)、11.2(空間のベクトル)、座標軸とベクトルの問8の解答を求めてみる。



    1. - 6 , 3 , 2 = 36 + 9 + 4 = 7

    2. 2 - 3 , 2 + 3 , 6 = 2 - 3 2 + 2 + 3 2 + 36 = 8 + 6 + 36 = 5 2

コード

#!/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()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

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

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

OK
%

0 コメント:

コメントを投稿