2020年1月3日金曜日

学習環境

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の2章(ベクトル空間)、3(基底)、練習問題2の解答を求めてみる。



    1. x 1 = 1 1 + x 2 = 0 1 , - 1

    2. x 1 + x 2 = 2 - x 1 + x 2 = 1 2 x 2 = 3 x 2 = 3 2 x 1 = 1 2 1 2 , 3 2

    3. x 1 = 1 2 - x 2 = 1 x 2 = 1 1 , 1

    4. x 1 = 3 6 - x 2 = 4 x 2 = 2 3 , 2

コード

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

print('2.')


class MyTestCase(TestCase):
    def test(self):
        Xs = [(1, 0), (2, 1), (1, 1), (4, 3)]
        As = [(1, 1), (1, -1), (2, 1), (2, 1)]
        Bs = [(0, 1), (1, 1), (-1, 0), (-1, 0)]
        xs = [(1, -1), (Rational(1, 2), Rational(3, 2)), (1, 1), (3, 2)]
        for X, A, B, (x1, x2) in zip(Xs, As, Bs, xs):
            self.assertEqual(Matrix(X), x1 * Matrix(A) + x2 * Matrix(B))


if __name__ == '__main__':
    main()

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

% ./sample2.py -v
2.
test (__main__.MyTestCase) ... ok

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

OK
%

0 コメント:

コメントを投稿