2020年3月2日月曜日

学習環境

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の4章(線形写像)、1(写像)、練習問題3の解答を求めてみる。



    1. L 1 , 2 , - 3 = 2 , 3 , - 1 · 1 , 2 , - 3 = 2 + 6 + 3 = 11

    2. 2 , 3 , - 1 · - 1 , 5 , 0 = - 2 + 15 = 13

    3. 2 , 3 , - 1 · 2 , 1 , 1 = 4 + 3 - 1 = 6

コード

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

print('3.')

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


class MyTestCase(TestCase):
    def test_a(self):
        self.assertEqual(a.dot(Matrix([1, 2, -3])), 11)

    def test_b(self):
        self.assertEqual(a.dot(Matrix([-1, 5, 0])), 13)

    def test_c(self):
        self.assertEqual(a.dot(Matrix([2, 1, 1])), 6)


if __name__ == '__main__':
    main()

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

% ./sample3.py -v
3.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok
test_c (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.040s

OK
%

0 コメント:

コメントを投稿