## 2020年5月3日日曜日

### 数学 - Python - 代数学 - 連立方程式と高次方程式 - 連立3元1次方程式の解

1. $\begin{array}{l}5x+5y+5z=-10\\ x+y+z=-2\\ 2z-2=2\\ z=2\\ 2y-2=-5\\ y=-\frac{3}{2}\\ 2x-2=-7\\ x=-\frac{5}{2}\end{array}$

2. $\begin{array}{l}x=2y+2\\ z=\frac{2y+2+1}{3}=\frac{2y+3}{3}\\ 4\left(2y+2\right)+y-\frac{2y+3}{3}=2\\ 24y+24+3y-2y-3=6\\ 25y=-15\\ y=-\frac{3}{5}\\ x=-\frac{6}{5}+2=\frac{4}{5}\\ z\\ =\frac{2\left(-\frac{3}{5}\right)+3}{3}\\ =-\frac{2}{5}+1\\ =\frac{3}{5}\end{array}$

コード

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

print('1.')

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

class TestCube(TestCase):
def test1(self):
self.assertEqual(
solve([x + y + 3 * z - 2,
x + 3 * y + z + 5,
3 * x + y + z + 7]),
{x: -Rational(5, 2), y: -Rational(3, 2), z: 2})

def test2(self):
self.assertEqual(
solve([2 * y - x + 2,
3 * z - x - 1,
4 * x + y - z - 2]),
{x: Rational(4, 5), y: -Rational(3, 5), z: Rational(3, 5)})

if __name__ == "__main__":
main()


% ./sample1.py -v
1.
test1 (__main__.TestCube) ... ok
test2 (__main__.TestCube) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.066s

OK
%