2020年6月25日木曜日

学習環境

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


  1. φ B ( A + C )
    = ( A + C ) B - B ( A + C )
    = A B + C B - B A - B C = A B - B A + C B - B C = φ B ( A ) + φ B ( C )
    φ B ( c A )
    = ( c A ) B - B ( c A )
    = c ( A B ) - c ( B A )
    = c ( A B - B A )
    = c φ B ( A )

    よって、線形写像である。

    (証明終)

    φ B ( I ) = O

    よって、 この線形写像は可逆ではない。

    ゆえにこの行列式の値は0である。

    (証明終)

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, symbols, MatrixSymbol
from sympy.abc import c

print('1.')

A = MatrixSymbol('A', 4, 4)
B = Matrix(symbols('b:16')).reshape(4, 4)
C = Matrix(symbols('c:16')).reshape(4, 4)
D = Matrix(symbols('d:16')).reshape(4, 4)
f = A * B - B * A


def eq(A, B):
    return all([a == b for a, b in zip(A, B)])


class Test(TestCase):
    def test_add(self):
        self.assertTrue(
            eq(
                f.subs({A: C + D}),
                f.subs({A: B}) + f.subs({A: C})
            )
        )

    def test_scalar_mul(self):
        self.assertTrue(
            eq(
                f.subs({A: c * C}),
                c * f.subs({A: C}),
            )
        )


if __name__ == "__main__":
    main()

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

% ./sample1.py -v
1.
test_add (__main__.Test) ... ok
test_scalar_mul (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.065s

OK
%

0 コメント:

コメントを投稿