2020年2月14日金曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第9章(図形と代数の交錯する世界 - 平面上のベクトル)、9.1(ベクトルとその演算)、平行四辺形の面積の問21の解答を求めてみる。



    1. S=15+4=19

    2. S=-2-56=58

    3. a+b=8a+b2=64a+b·a+b=64a2+2a·b+b2=6416+2a·b-7+36=64a·b=12S=a2b2-a·b2=16·36-144=432=42·33=123

コード

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

print('21.')


def s(a, b):
    return sqrt(a.norm() ** 2 * b.norm() ** 2 - a.dot(b) ** 2)


class MyTestCase(TestCase):
    def test1(self):
        a = Matrix([5, 1])
        b = Matrix([-4, 3])
        self.assertEqual(s(a, b), 19)

    def test2(self):
        a = Matrix([1, 8])
        b = Matrix([7, -2])
        self.assertEqual(s(a, b), 58)

    def test3(self):
        self.assertEqual(sqrt(4 ** 2 * 6 ** 2 - 12 ** 2), 12 * sqrt(3))


if __name__ == "__main__":
    main()

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

% ./sample21.py -v
21.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.048s

OK
%

0 コメント:

コメントを投稿