2020年6月5日金曜日

学習環境

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


  1. 問題の仮定より、ベクトル A はそれ自身と直交するので

    A · A = 0 A 2 = 0

    よって、

    A = O

    である。

    (証明終)

コード

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

print('5.')


class TestScalarProduct(TestCase):
    def test(self):
        a0, a1 = symbols('a:2')
        a = Matrix([a0, a1])
        self.assertEqual(solve([Matrix([random.randrange(-10, 11),
                                        random.randrange(-10, 11)]).dot(a)
                                for _ in range(10)]),
                         {a0: 0, a1: 0})


if __name__ == "__main__":
    main()

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

% ./sample5.py -v
5.
test (__main__.TestScalarProduct) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.064s

OK
%

0 コメント:

コメントを投稿