学習環境
- Surface
 - Windows 10 Pro (OS)
 - Nebo(Windows アプリ)
 - iPad
 - MyScript Nebo - MyScript(iPad アプリ(iOS))
 - 参考書籍
 
ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の5章(線形写像と行列)、3(線形写像の合成)、練習問題3の解答を求めてみる。
よって、問題の基底に関する恒等線形写像に対応する行列は、
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, solve, Rational
print('3.')
class Test(TestCase):
    def test_a(self):
        A = Matrix(symbols('a:9')).reshape(3, 3)
        X = Matrix([[1, 1, 0],
                    [-1, 1, 1],
                    [0, 1, 2]])
        s = solve(A * Matrix([[2, 1, 1],
                              [0, 0, 1],
                              [-1, 1, 1]]) - X)
        self.assertEqual(Matrix(list(s.values())).reshape(3, 3).T,
                         Matrix([[Rational(2, 3), 0, Rational(1, 3)],
                                 [-1, 0, 1],
                                 [Rational(1, 3), 1, Rational(2, 3)]]))
    def test_b(self):
        A = Matrix(symbols('a:9')).reshape(3, 3)
        X = Matrix([[3, 2, 1],
                    [0, -2, 5],
                    [1, 1, 2]])
        s = solve(A * Matrix([[1, 1, 0],
                              [-1, 2, 4],
                              [2, -1, 1]]) - X)
        self.assertEqual(Matrix(list(s.values())).reshape(3, 3).T,
                         Rational(1, 15) * Matrix([[33, -33, 9],
                                                   [2, 13, 6],
                                                   [7, 23, 6]]))
if __name__ == "__main__":
    main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample3.py -v
3.
test_a (__main__.Test) ... ok
test_b (__main__.Test) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.130s
OK
%
0 コメント:
コメントを投稿