## 2020年1月2日木曜日

### 数学 - Python - 線形代数学 - ベクトル空間 - 基底 - 一次独立、体、実数上、複素数上

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

1. $\begin{array}{l}a\left(1,1,1\right)+b\left(0,1,-1\right)=O\\ a=0\\ b=0\end{array}$

よって1次独立。

2. $\begin{array}{l}a+b=0\\ b=0\\ a=0\end{array}$

3. $\begin{array}{l}-a=0\\ a+b=0\\ 2b=0\\ a=0\\ b=0\end{array}$

4. $\begin{array}{l}2a+b=0\\ -a=0\\ a=0\\ b=0\end{array}$

5. $\begin{array}{l}a\pi =0\\ b=0\\ a=0\end{array}$

6. $\begin{array}{l}a+b=0\\ 2a+3b=0\\ b=-a\\ 2a-3b=0\\ b=0\\ a=0\end{array}$

7. $\begin{array}{l}\left\{\begin{array}{l}a+b=0\\ a+b+c=0\\ b-c=0\end{array}\\ b=-a\\ c=-a\\ a-a-a=0\\ a=0\\ b=0\\ c=0\end{array}$

8. $\begin{array}{l}c=0\\ a+2b=0\\ a+b=0\\ b=0\\ a=0\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, solve, pi

print('1')

a, b, c = symbols('a, b, c')

class MyTestCase(TestCase):
def test2(self):
egg = [((1, 1, 1), (0, 1, -1)),
((1, 0), (1, 1)),
((-1, 1, 0), (0, 1, 2)),
((2, -1), (1, 0)),
((pi, 0), (0, 1)),
((1, 2), (1, 3))]
for u, v in egg:
s = solve(a * Matrix(u) + b * Matrix(v))
for n in s.values():
self.assertEqual(n, 0)

def test3(self):
egg = [((1, 1, 0), (1, 1, 1), (0, 1, -1)),
((0, 1, 1), (0, 2, 1), (1, 5, 3))]
for u, v, w in egg:
s = solve(a * Matrix(u) + b * Matrix(v) + c * Matrix(w))
for n in s.values():
self.assertEqual(n, 0)

if __name__ == '__main__':
main()


% ./sample1.py -v
1
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.083s

OK
%