2020年1月7日火曜日

学習環境

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



    1. c 1 t + c 2 1 t = 0 c 1 t 2 + c 2 = 0 2 c 1 t = 0 c 1 = 0 c 2 = 0

      よって、 1次独立。


    2. c 1 e t + c 2 log t = 0 c 1 e t + c 2 t = 0 c 1 t e t + c 2 = 0 c 1 e t + t e t = 0 c 1 e t 1 + t = 0 c 1 = 0 c 2 = 0

コード

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

print('6.')
t = symbols('t', real=True, positive=True)
c1, c2 = symbols('c1, c2', imag=True)
cs = [c1, c2]
fs = [t, 1 / t]
gs = [exp(t), log(t)]


class LinearlyIndependentTestCase(TestCase):
    def test_a(self):
        inear_combination = sum([c * f for c, f in zip(cs, fs)])
        self.assertEqual(solve(inear_combination, c1, c2), {c1: 0, c2: 0})

    def test_b(self):
        inear_combination = sum([c * g for c, g in zip(cs, gs)])
        self.assertEqual(solve(inear_combination, c1, c2), {c1: 0, c2: 0})


p = plot(*fs, *gs,
         (t, -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('sample6.png')

if __name__ == '__main__':
    main()

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

% ./sample6.py -v
6.
test_a (__main__.LinearlyIndependentTestCase) ... ok
test_b (__main__.LinearlyIndependentTestCase) ... FAIL

======================================================================
FAIL: test_b (__main__.LinearlyIndependentTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./sample6.py", line 19, in test_b
    self.assertEqual(solve(inear_combination, c1, c2), {c1: 0, c2: 0})
AssertionError: [(-c2*exp(-t)*log(t), c2)] != {c1: 0, c2: 0}

----------------------------------------------------------------------
Ran 2 tests in 0.356s

FAILED (failures=1)
%

0 コメント:

コメントを投稿