## 2020年3月4日水曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 解の係数の関係、2次式の因数分解 - 2変数の場合

1. $\begin{array}{l}\frac{-1±\sqrt{1+48}}{4}\\ =\frac{-1±7}{4}\\ =-2,\frac{3}{2}\end{array}$

よって、

$\begin{array}{l}2\left(x+2y\right)\left(x-\frac{3}{2}y\right)\\ =\left(x+2y\right)\left(2x-3y\right)\end{array}$

2. $\begin{array}{l}\frac{7±\sqrt{49-36}}{6}\\ =\frac{7±\sqrt{13}}{6}\\ 3\left(x-\frac{7-\sqrt{13}}{6}y\right)\left(x-\frac{7+\sqrt{13}}{6}y\right)\end{array}$

3. $\begin{array}{l}\frac{-1±\sqrt{1-4}}{2}\\ =\frac{-1±\sqrt{3}i}{2}\\ \left(x-\frac{-1-\sqrt{3}i}{2}y\right)\left(x-\frac{-1+\sqrt{3}i}{2}y\right)\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, sqrt, I, pprint
from sympy.plotting import plot3d

print('30.')

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

abcs = [(2, 1, -6),
(3, -7, 3),
(1, 1, 1)]
fs = [a * x ** 2 + b * x * y + c * y ** 2 for a, b, c in abcs]

class MyTestCase(TestCase):
def test(self):

facts = [(x + 2 * y) * (2 * x - 3 * y),
3 * (x - (7 - sqrt(13)) / 6 * y) *
(x - (7 + sqrt(13)) / 6 * y),
(x - (-1 - sqrt(3) * I) / 2 * y) * (x - (- 1 + sqrt(3) * I) / 2 * y)]
for i, (f, fact) in enumerate(zip(fs, facts), 1):
print(f'({i})')
self.assertEqual(f, fact.expand())

p = plot3d(*fs,
show=False,
xlabel=x,
ylabel=y)

p.show()
p.save('sample30.png')

if __name__ == "__main__":
main()


% ./sample30.py
30.
(1)
(2)
(3)
.
----------------------------------------------------------------------
Ran 1 test in 0.025s

OK
%