2020年5月24日日曜日

学習環境

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



    1. 1 , 1 , 0 = a 11 2 , 1 , 1 + a 21 0 , 0 , 1 + a 31 - 1 , 1 , 1 - 1 , 1 , 1 = a 12 2 , 1 , 1 + a 22 0 , 0 , 1 + a 32 - 1 , 1 , 1 0 , 1 , 2 = a 13 2 , 1 , 1 + a 23 0 , 0 , 1 + a 33 - 1 , 1 , 1 { 2 a 11 - a 31 = 1 a 11 + a 31 = 1 a 11 + a 21 + a 31 = 0 3 a 11 = 2 a 11 = 2 3 a 31 = 1 3 a 21 = - 1 { 2 a 12 - a 32 = - 1 a 12 + a 32 = 1 a 12 + a 22 + a 32 = 1 a 12 = 0 a 32 = 1 a 22 = 0 { 2 a 13 - a 33 = 0 a 13 + a 33 = 1 a 13 + a 23 + a 33 = 2 a 13 = 1 3 a 33 = 2 3 a 23 = 1

      よって、問題の基底に関する恒等線形写像に対応する行列は、

      [ 2 3 0 1 3 - 1 0 1 1 3 1 2 3 ]

    2. 3 , 2 , 1 = a 11 1 , 1 , 0 + a 21 - 1 , 2 , 4 + a 31 2 , - 1 , 1 0 , - 2 , 5 = a 12 1 , 1 , 0 + a 22 - 1 , 2 , 4 + a 32 2 , - 1 , 1 1 , 1 , 2 = a 13 1 , 1 , 0 + a 23 - 1 , 2 , 4 + a 33 2 , - 1 , 1 { a 11 - a 21 + 2 a 31 = 3 a 11 + 2 a 21 - a 31 = 2 4 a 21 + a 31 = 1 a 31 = 1 - 4 a 21 a 11 - 9 a 21 = 1 a 11 + 6 a 21 = 3 15 a 21 = 2 a 21 = 2 15 a 31 = 7 15 a 11 = 33 15 { a 12 - a 22 + 2 a 32 = 0 a 12 + 2 a 22 - a 32 = - 2 4 a 22 + a 32 = 5 a 32 = 5 - 4 a 22 a 12 - 9 a 22 = - 10 a 12 + 6 a 22 = 3 a 22 = 13 15 a 32 = 23 15 a 12 = 45 15 - 78 15 = - 33 15 { a 13 - a 23 + 2 a 33 = 1 a 13 + 2 a 23 - a 33 = 1 4 a 23 + a 33 = 2 a 33 = 2 - 4 a 23 a 13 - 9 a 23 = - 3 a 13 + 6 a 23 = 3 a 23 = 6 15 a 33 = 6 15 a 13 = 9 15 1 15 [ 33 - 33 9 2 13 6 7 23 6 ]

コード

#!/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 コメント:

コメントを投稿