## 2020年2月13日木曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 複素数 - 3次式

1.
$\begin{array}{l}x=\frac{3+2i}{1-i}\\ =\frac{\left(3+2i\right)\left(1+i\right)}{2}\\ =\frac{1+5i}{2}\\ {x}^{2}=\frac{-24+10i}{4}=\frac{-12+5i}{2}\\ {x}^{3}+2{x}^{2}+3x+4\\ ={\left(\frac{1+5i}{2}\right)}^{3}+2{\left(\frac{1+5i}{2}\right)}^{2}+3·\frac{1+5i}{2}+4\\ =\left(\frac{-12+5i}{2}\right)·\frac{1+5i}{2}-12+5i+\frac{3+15i}{2}+4\\ =\frac{-37-55i}{4}-8+5i+\frac{3+15i}{2}\\ =\frac{-63-5i}{4}\end{array}$

コード

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

print('14.')

x = symbols('x')
f = x ** 3 + 2 * x ** 2 + 3 * x + 4

class MyTestCase(TestCase):
def test(self):
x0 = (3 + 2 * I) / (1 - I)
self.assertEqual(f.subs({x: x0}).expand(), (-63 - 5 * I) / 4)

p = plot(f,
ylim=(-10, 10),
legend=True,
show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange', 'pink']

for i, s in enumerate(p):
s.line_color = colors[i]

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

if __name__ == "__main__":
main()


% ./sample14.py -v
14.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.011s

OK
%