## 2020年3月2日月曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 解の係数の関係、2次式の因数分解 - 複素数の範囲

1. $\begin{array}{l}56{x}^{2}+89x+35\\ =\left(7x+5\right)\left(8x+7\right)\end{array}$

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

3. $\left(2x-7\right)\left(12x+5\right)$

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

5. $\begin{array}{l}9{x}^{2}+25\\ =\left(3x-5i\right)\left(3x+5i\right)\end{array}$

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

7. $\begin{array}{l}x\\ =\frac{7\sqrt{2}±\sqrt{98-26}}{2}\\ =\frac{7\sqrt{2}±\sqrt{72}}{2}\\ =\frac{7\sqrt{2}±6\sqrt{2}}{2}\\ =\frac{\sqrt{2}}{2},\frac{13\sqrt{2}}{2}\\ 2\left(x-\frac{\sqrt{2}}{2}\right)\left(x-\frac{13\sqrt{2}}{2}\right)\end{array}$

8. $\begin{array}{l}x\\ =\frac{\sqrt{11}±\sqrt{11-4·5}}{2\sqrt{5}}\\ =\frac{\sqrt{11}±3i}{2\sqrt{5}}\\ =\frac{\sqrt{55}±3\sqrt{5}i}{10}\\ \sqrt{5}\left(x-\frac{\sqrt{55}-3\sqrt{5}i}{10}\right)\left(x-\frac{\sqrt{55}+3\sqrt{5}i}{10}\right)\end{array}$

コード

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

print('28.')

x = symbols('x', image=True)
abcs = [(56, 89, 35),
(3, 2, -4),
(24, -74, -35),
(3, -4, -2),
(9, 0, 25),
(1, -1, 1),
(2, -14 * sqrt(2), 13),
(sqrt(5), -sqrt(11), sqrt(5))]
fs = [a * x ** 2 + b * x + c for a, b, c in abcs]
gs = [(7 * x + 5) * (8 * x + 7),
3 * (x - (-1-sqrt(13)) / 3) * (x - (-1 + sqrt(13)) / 3),
(2 * x - 7) * (12 * x + 5),
3 * (x - (2 - sqrt(10)) / 3) * (x - (2 + sqrt(10)) / 3),
(3 * x - 5 * I) * (3 * x + 5 * I),
(x - (1 - sqrt(3) * I) / 2) * (x - (1 + sqrt(3) * I) / 2),
2 * (x - sqrt(2) / 2) * (x - 13 * sqrt(2) / 2),
sqrt(5) * (x - (sqrt(55) - 3 * sqrt(5) * I) / 10) *
(x - (sqrt(55) + 3 * sqrt(5) * I) / 10)
]

class MyTestCase(TestCase):
def test(self):
for i, (f, g) in enumerate(zip(fs, gs), 1):
print(f'({i})')
self.assertEqual(f, g.expand())

p = plot(*fs,
ylim=(-10, 10),
legend=False,
show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for i, s in enumerate(p):
s.line_color = colors[i]

for o in zip(p, colors):
pprint(o)
for i, f in enumerate(fs, 1):
print(f'({i})')
pprint(f.factor(gaussian=True))

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

if __name__ == "__main__":
main()


% ./sample28.py -v
28.
(cartesian line: 56*x**2 + 89*x + 35 for x over (-10.0, 10.0), red)
(cartesian line: 3*x**2 + 2*x - 4 for x over (-10.0, 10.0), green)
(cartesian line: 24*x**2 - 74*x - 35 for x over (-10.0, 10.0), blue)
(cartesian line: 3*x**2 - 4*x - 2 for x over (-10.0, 10.0), brown)
(cartesian line: 9*x**2 + 25 for x over (-10.0, 10.0), orange)
(cartesian line: x**2 - x + 1 for x over (-10.0, 10.0), purple)
(cartesian line: 2*x**2 - 14*sqrt(2)*x + 13 for x over (-10.0, 10.0), pink)
(cartesian line: sqrt(5)*x**2 - sqrt(11)*x + sqrt(5) for x over (-10.0, 10.0), g
ray)
(1)
56⋅(x + 5/7)⋅(x + 7/8)
(2)
⎛ 2   2⋅x   4⎞
3⋅⎜x  + ─── - ─⎟
⎝      3    3⎠
(3)
24⋅(x - 7/2)⋅(x + 5/12)
(4)
⎛ 2   4⋅x   2⎞
3⋅⎜x  - ─── - ─⎟
⎝      3    3⎠
(5)
⎛    5⋅ⅈ⎞ ⎛    5⋅ⅈ⎞
9⋅⎜x - ───⎟⋅⎜x + ───⎟
⎝     3 ⎠ ⎝     3 ⎠
(6)
2
x  - x + 1
(7)
⎛ 2            13⎞
2⋅⎜x  - 7⋅√2⋅x + ──⎟
⎝              2 ⎠
(8)
2
√5⋅x  - √11⋅x + √5
test (__main__.MyTestCase) ... (1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
ok

----------------------------------------------------------------------
Ran 1 test in 0.012s

OK
%