2019年1月24日木曜日

数学 - Python - 線形代数学 - 行列 – 1次方程式(複素数における連立1次方程式の解、消去法)

ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の3章(行列)、2(1次方程式)、練習問題4の解答を求めてみる。

1. $\begin{array}{}x=2-iy\\ 2i+y-2y=1\\ y=2i-1\\ x=2+2+i\\ =4+i\end{array}$

2. $\begin{array}{}x=2y-iz\\ y=ix+\left(2-i\right)z+1\\ =2iy+z+\left(2-i\right)z+1\\ \left(1-2i\right)y=\left(3-i\right)z+1\\ y=\frac{\left(3-i\right)z+1}{1-2i}\\ =\frac{\left(3-i\right)\left(1+2i\right)z+\left(1+2i\right)}{1+4}\\ =\frac{\left(5+5i\right)z+\left(1+2i\right)}{5}\\ =\left(1+i\right)z+\frac{1+2i}{5}\\ x=2\left(1+i\right)z+\frac{2\left(1+2i\right)}{5}-iz\\ =\left(2+i\right)z+\frac{2\left(1+2i\right)}{5}\\ 2\left(2+i\right)z+\frac{4\left(1+2i\right)}{5}+\left(i-1\right)z+\frac{i-2}{5}-\left(1+i\right)z=1\\ 2\left(1+i\right)z=1-\frac{2+9i}{5}\\ 2\left(1+i\right)z=\frac{3-9i}{5}\\ z=\frac{3\left(1-3i\right)}{10\left(1+i\right)}\\ =\frac{3\left(1-3i\right)\left(1-i\right)}{10·2}\\ =\frac{3\left(-2-4i\right)}{10·2}\\ =\frac{-3\left(1+2i\right)}{10}\\ x=\frac{-3\left(1+2i\right)\left(2+i\right)}{10}+\frac{2\left(1+2i\right)}{5}\\ =\frac{-3·5i}{10}+\frac{2\left(1+2i\right)}{5}\\ =\frac{-15i+8i+4}{10}\\ =-\frac{7}{10}i+\frac{2}{5}\\ y=\frac{-3\left(1+2i\right)\left(1+i\right)}{10}+\frac{1+2i}{5}\\ =\frac{-3\left(-1+3i\right)}{10}+\frac{2+4i}{10}\\ =\frac{5-5i}{10}\\ =\frac{1-i}{2}\end{array}$

3. $\begin{array}{}y=\left(1+i\right)x\\ ix+\left(1+i\right)x=3-i\\ x=\frac{3-i}{1+2i}\\ =\frac{\left(3-i\right)\left(1-2i\right)}{1+4}\\ =\frac{1-7i}{5}\\ y=\frac{\left(1-7i\right)\left(1+i\right)}{5}\\ =\frac{8-6i}{5}\end{array}$

4. $\begin{array}{}x=1+i-\left(2-i\right)y\\ i-1-\left(2i+1\right)y-\left(2+i\right)y=1\\ y=\frac{2-i}{-3i-3}\\ =\frac{2-i}{-3\left(1+i\right)}\\ =\frac{\left(2-i\right)\left(1-i\right)}{-3·2}\\ =\frac{1-3i}{-3·2}\\ =\frac{-1+3i}{6}\\ x=1+i-\frac{\left(-1+3i\right)\left(2-i\right)}{6}\\ =1+i-\frac{1+7i}{6}\\ =\frac{5-i}{6}\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, solve, I
print('3.')

x, y, z = symbols('x, y, z')

ts = [(I * x - 2 * y - 1,
x + I * y - 2),
(2 * x + I * y - (1 + I) * z - 1,
x - 2 * y + I * z,
-I * x + y - (2 - I) * z - 1),
((1 + I) * x - y,
I * x + y - (3 - I)),
(I * x - (2 + I) * y - 1,
x + (2 - I) * y - (1 + I))]

for i, t in enumerate(ts):
print(f'({chr(ord("a") + i)})')
pprint(solve(t, x, y, z))
print()


$python3 sample4.py 3. (a) {x: 4 + ⅈ, y: ⅈ⋅(2 + ⅈ)} (b) ⎧ 2 7⋅ⅈ 1 ⅈ 3 3⋅ⅈ⎫ ⎨x: ─ - ───, y: ─ - ─, z: - ── - ───⎬ ⎩ 5 10 2 2 10 5 ⎭ (c) ⎧ 2⎫ ⎪ 1 7⋅ⅈ (3 - ⅈ) ⎪ ⎨x: ─ - ───, y: ────────⎬ ⎪ 5 5 5 ⎪ ⎩ ⎭ (d) ⎧ 5 ⅈ 1 ⅈ⎫ ⎨x: ─ - ─, y: - ─ + ─⎬ ⎩ 6 6 6 2⎭$