## 2020年4月4日土曜日

### 数学 - Python - 解析学 - n次元空間 - ベクトル空間 - 基底、標準基底の座標

1. $\begin{array}{l}\left\{\begin{array}{l}b-c={e}_{1}\\ -a+c={e}_{2}\\ a+2b={e}_{3}\end{array}\\ c=a+{e}_{2}\\ b=a+{e}_{2}+{e}_{1}\\ a+2a+2{e}_{2}+2{e}_{1}={e}_{3}\\ a=\frac{1}{3}\left(-2{e}_{1}-2{e}_{2}+{e}_{3}\right)\\ =\frac{1}{3}\left(-2,-2,1\right)\\ b=\frac{1}{3}\left(-2,-2,1\right)+{e}_{2}+{e}_{1}\\ =\frac{1}{3}\left(1,1,1\right)\\ c=\frac{1}{3}\left(-2,-2,1\right)+{e}_{2}\\ =\frac{1}{3}\left(-2,1,1\right)\end{array}$

コード

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

print('2.')

a = Matrix(symbols('a:3'))
b = Matrix(symbols('b:3'))
c = Matrix(symbols('c:3'))

class Test(TestCase):
def test(self):
self.assertEqual(solve([0 * a + 1 * b - c - Matrix([1, 0, 0]),
-1 * a + c - Matrix([0, 1, 0]),
a + 2 * b - Matrix([0, 0, 1])]),
{k: Rational(1, 3) * v
for k, v in zip(symbols('a:3 b:3 c:3'),
[-2, -2, 1,
1, 1, 1,
-2, 1, 1])})

if __name__ == "__main__":
main()


% ./sample2.py -v
2.
test (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.074s

OK
%