2020年7月9日木曜日

学習環境

続 解析入門 (原書第2版) (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第1章(ベクトル)、7(ベクトル積)の練習問題4の解答を求めてみる。



    1. A×A
      =(1,-1,1)×(1,-1,1)
      =(-1-(-1),1-1,-1-(-1))
      =(0,0,0)
      B×B
      =(-2,3,1)×(-2,3,1)
      =(3-3,2-(-2),-6-(-6))
      =(0,0,0)

    2. (2-2,-2-(-2),-1-(-1))=(0,0,0)
      B×B=O

    3. A×A=O,B×B=AO

コード

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

print('4.')

a = [(1, -1, 1),
     (-1, 1, 2),
     (1, 1, -3)]
b = [(-2, 3, 1),
     (1, 0, -1),
     (-1, -2, -3)]


class TestCross(TestCase):
    def test(self):
        for o in a + b:
            x = Matrix(o)
            self.assertEqual(x.cross(x), Matrix([0, 0, 0]))


if __name__ == "__main__":
    main()

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

% ./sample4.py -v
4.
test (__main__.TestCross) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
%

0 コメント:

コメントを投稿