## 2020年1月4日土曜日

### 数学 - Python - 線形代数学 - ベクトル空間 - 基底 - 3次、一次結合、座標ベクトル

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

1. $\begin{array}{l}\left\{\begin{array}{l}{x}_{1}-{x}_{2}+{x}_{3}=1\\ {x}_{1}+{x}_{2}=0\\ {x}_{1}-{x}_{3}=0\end{array}\\ {x}_{2}=-{x}_{1}\\ {x}_{3}={x}_{1}\\ {x}_{1}+{x}_{1}+{x}_{1}=1\\ {x}_{1}=\frac{1}{3}\\ \left(\frac{1}{3},-\frac{1}{3},\frac{1}{3}\right)\end{array}$

2. $\begin{array}{l}\left\{\begin{array}{l}{x}_{2}+{x}_{3}=1\\ {x}_{1}+{x}_{2}=1\\ -{x}_{1}+2{x}_{3}=1\end{array}\\ {x}_{1}-{x}_{3}=0\\ {x}_{3}=1\\ {x}_{1}=1\\ {x}_{2}=0\\ \left(1,0,1\right)\end{array}$

3. $\begin{array}{l}\left\{\begin{array}{l}{x}_{1}-{x}_{2}+{x}_{3}=0\\ {x}_{1}+{x}_{2}=0\\ {x}_{1}-{x}_{3}=1\end{array}\\ {x}_{2}=-{x}_{1}\\ {x}_{3}={x}_{1}-1\\ {x}_{1}+{x}_{1}+{x}_{1}-1=0\\ {x}_{1}=\frac{1}{3}\\ \left(\frac{1}{3},-\frac{1}{3},-\frac{2}{3}\right)\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, Rational

print('3.')

class MyTestCase(TestCase):
def test(self):
Xs = [(1, 0, 0), (1, 1, 1), (0, 0, 1)]
As = [(1, 1, 1), (0, 1, -1), (1, 1, 1)]
Bs = [(-1, 1, 0), (1, 1, 0), (-1, 1, 0)]
Cs = [(1, 0, -1), (1, 0, 2), (1, 0, -1)]
xs = [(Rational(1, 3), -Rational(1, 3), Rational(1, 3)),
(1, 0, 1),
(Rational(1, 3), -Rational(1, 3), -Rational(2, 3))]
for X, A, B, C, (x1, x2, x3) in zip(Xs, As, Bs, Cs, xs):
self.assertEqual(Matrix(X), x1 * Matrix(A) +
x2 * Matrix(B) + x3 * Matrix(C))

if __name__ == '__main__':
main()


% ./sample3.py -v
3.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
%