## 2017年12月22日金曜日

### 数学 - Python - もう１つの数学の基盤 - 行列と行列式 – 連立1次方程式と行列式 - n = 3 の場合(行列式による3元連立1次方程式の解法)

1. $\begin{array}{}\mathrm{det}\left(\begin{array}{ccc}3& 2& 1\\ 4& 3& -1\\ 5& 4& 1\end{array}\right)\end{array}=\mathrm{det}\left(\begin{array}{ccc}3& 2& 1\\ 7& 5& 0\\ 2& 2& 0\end{array}\right)\\ =14-10\\ =4$
$\begin{array}{}x\\ =\frac{1}{4}\mathrm{det}\left(\begin{array}{ccc}2& 2& 1\\ -2& 3& -1\\ 6& 4& 1\end{array}\right)\end{array}=\frac{1}{4}\mathrm{det}\left(\begin{array}{ccc}0& 0& 1\\ 0& 5& -1\\ 4& 2& 1\end{array}\right)\\ =\frac{1}{4}·\left(-20\right)\\ =-5$
$\begin{array}{}y\\ =\frac{1}{4}\mathrm{det}\left(\begin{array}{ccc}3& 2& 1\\ 4& -2& -1\\ 5& 6& 1\end{array}\right)\end{array}=\frac{1}{4}\left(\begin{array}{ccc}3& 2& 1\\ 7& 0& 0\\ 2& 4& 0\end{array}\right)\\ =\frac{1}{4}\left(-7\right)\left(-4\right)\\ =7$
$\begin{array}{}z\\ =\frac{1}{4}\mathrm{det}\left(\begin{array}{ccc}3& 2& 2\\ 4& 3& -2\\ 5& 4& 6\end{array}\right)\end{array}=\frac{1}{4}\left(\begin{array}{ccc}3& 2& 2\\ 7& 5& 0\\ -4& -2& 0\end{array}\right)\\ =\frac{1}{2}\left(-14+20\right)\\ =3$

2. $\begin{array}{}\mathrm{det}\left(\begin{array}{ccc}1& 3& -5\\ 3& 2& 3\\ 2& -6& 13\end{array}\right)\end{array}=\mathrm{det}\left(\begin{array}{ccc}1& 3& -5\\ 0& -7& 18\\ 0& -12& 23\end{array}\right)\\ =-161+216\\ =55$
$\begin{array}{}x\\ =\frac{1}{55}\mathrm{det}\left(\begin{array}{ccc}5& 3& -5\\ 0& 2& 3\\ 0& -6& 13\end{array}\right)\end{array}=\frac{1}{11}\left(26+18\right)\\ =4$
$\begin{array}{}y\\ =\frac{1}{55}\mathrm{det}\left(\begin{array}{ccc}1& 5& -5\\ 3& 0& 3\\ 2& 0& 13\end{array}\right)\end{array}=-\frac{1}{11}\left(39-6\right)\\ =-3$
$\begin{array}{}z\\ =\frac{1}{55}\mathrm{det}\left(\begin{array}{ccc}1& 3& 5\\ 3& 2& 0\\ 2& -6& 0\end{array}\right)\end{array}=\frac{1}{11}\left(-18-4\right)\\ =-2$

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, solve, Matrix

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

eqs = [
(
3 * x + 2 * y + z - 2,
4 * x + 3 * y - z + 2,
5 * x + 4 * y + z - 6
),
(
x + 3 * y - 5 * z - 5,
3 * x + 2 * y + 3 * z,
2 * x - 6 * y + 13 * z
)
]

for i, eqs0 in enumerate(eqs, 1):
print(f'({i})')
pprint(solve(eqs0, (x, y, z)))


$./sample37.py (1) {x: -5, y: 7, z: 3} (2) {x: 4, y: -3, z: -2}$