2020年5月8日金曜日

学習環境

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



    • v を 問題のベクトル空間の任意の元とする。

      A+B2v=A+BA+Bv=A+BAv+Bv=AAv+Bv+BAv+Bv=AAv+ABv+BAv+BBv=A2V+ABv+BAv+B2v=A2v+ABv+ABv+B2v=A2v+2ABv+B2v=A2+2AB+B2v

      よって、

      A+B2=A2+2AB+B2

    • A+BA-B=A2-AB+BA-B2=A2-AB+AB-B2=A2-B2

コード

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

print('9.')

x = symbols('x', real=True)
a = 2 * x
b = x / 2


class TestKernel(TestCase):
    def test1(self):
        self.assertEqual((a + b).subs({x: a + b}),
                         a.subs({x: a}) + 2 * a.subs({x: b}) + b.subs({x: b}))

    def test2(self):
        self.assertEqual((a + b).subs({x: a - b}),
                         a.subs({x: a}) - b.subs({x: b}))


p = plot(a, b, a.subs({x: b}), b.subs({x: a}),
         (x, -5, 5),
         ylim=(-5, 5),
         legend=True,
         show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
    o.line_color = color
p.show()
p.save('sample9.png')


if __name__ == "__main__":
    main()

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

% ./sample9.py -v
9.
test1 (__main__.TestKernel) ... ok
test2 (__main__.TestKernel) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.037s

OK
%

0 コメント:

コメントを投稿