2020年1月21日火曜日

学習環境

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


  1. 成分表示。

    A B = 3 , 1 - - 1 , - 2 = 4 , 3 B C = 1 , 9 - 3 , 1 = - 2 , 8 C A = - 1 , - 2 - 1 , 9 = - 2 , - 11

    大きさ。

    A B = 4 2 + 3 2 = 16 + 9 = 25 = 5 B C = 4 + 64 = 2 1 + 16 = 2 17 C A = 4 + 121 = 125 = 5 5

コード

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

print('2.')

a = Matrix([-1, -2])
b = Matrix([3, 1])
c = Matrix([1, 9])


class MyTestCase(TestCase):
    def test_ab(self):
        t = b - a
        self.assertEqual(t, Matrix([4, 3]))
        self.assertEqual(t.norm(), 5)

    def test_bc(self):
        t = c - b
        self.assertEqual(t, Matrix([-2, 8]))
        self.assertEqual(t.norm(), 2 * sqrt(17))

    def test_ca(self):
        t = a - c
        self.assertEqual(t, Matrix([-2, -11]))
        self.assertEqual(t.norm(), 5 * sqrt(5))


if __name__ == '__main__':
    main()

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

% ./sample6.py -v
6.
test_ab (__main__.MyTestCase) ... ok
test_bc (__main__.MyTestCase) ... ok
test_ca (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.045s

OK
%

0 コメント:

コメントを投稿