## 2020年1月7日火曜日

### 数学 - Python - 線形代数学 - ベクトル空間 - 基底 - 実関数のなすベクトル空間、直線、逆数、指数関数、対数関数

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

1. $\begin{array}{l}{c}_{1}t+{c}_{2}\frac{1}{t}=0\\ {c}_{1}{t}^{2}+{c}_{2}=0\\ 2{c}_{1}t=0\\ {c}_{1}=0\\ {c}_{2}=0\end{array}$

よって、 1次独立。

2. $\begin{array}{l}{c}_{1}{e}^{t}+{c}_{2}\mathrm{log}t=0\\ {c}_{1}{e}^{t}+\frac{{c}_{2}}{t}=0\\ {c}_{1}t{e}^{t}+{c}_{2}=0\\ {c}_{1}\left({e}^{t}+t{e}^{t}\right)=0\\ {c}_{1}{e}^{t}\left(1+t\right)=0\\ {c}_{1}=0\\ {c}_{2}=0\end{array}$

コード

#!/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()


% ./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)
%