2020年5月15日金曜日

学習環境

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


  1. cos α = e 1 · a e 1 a = a 1 a

    同様に

    cos β = a 2 a cos γ = a 3 a

    よって、

    a a = cos α , cos β , cos γ

    である。

    (証明終)

コード

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

print('17.')

e1 = Matrix([1, 0, 0])
e2 = Matrix([0, 1, 0])
e3 = Matrix([0, 0, 1])
a1, a2, a3 = symbols('a1, a2, a3')
a = Matrix([a1, a2, a3])


class TestDirectionCosine(TestCase):
    def test(self):
        self.assertEqual(
            a / a.norm(),
            Matrix([e.dot(a) / (e.norm() * a.norm()) for e in [e1, e2, e3]]))


t = symbols('t')
l = [n for n in range(-5, 6) if n != 0]
p = plot3d_parametric_line(
    *[(t * random.choice(l),
       t * random.choice(l),
       t * random.choice(l),
       (t, 0, 1))
      for _ in range(5)],
    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.save('sample17.png')
p.show()

if __name__ == "__main__":
    main()

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

% ./sample17.py -v
17.
test (__main__.TestDirectionCosine) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.043s

OK
%

0 コメント:

コメントを投稿