## 2020年3月22日日曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 虚数、複素数、実部と虚部

1. $\begin{array}{l}\left({a}^{2}-2ab+3\right)+\left({a}^{2}-2a-8\right)i=0\\ {a}^{2}-2a-8=0\\ \left(a-4\right)\left(a+2\right)=0\\ a=-2,4\\ 4+4b+3=0\\ b=-\frac{7}{4}\\ 16-8b+3=0\\ b=\frac{19}{8}\end{array}$

よって、 求める a、 b の値は

$a=-2,b=-\frac{7}{4}$

または

$a=4,b=\frac{19}{8}$

2. $\begin{array}{l}b\ne 0\\ {\left(a+bi\right)}^{3}\\ ={a}^{3}+3{a}^{2}bi+3a{\left(bi\right)}^{2}+{\left(bi\right)}^{3}\\ =\left({a}^{3}-3a{b}^{2}\right)+\left(3{a}^{2}b-{b}^{3}\right)i\end{array}$

これが実数なので、

$\begin{array}{l}3{a}^{2}b-{b}^{3}=0\\ b\left(3{a}^{2}-{b}^{2}\right)=0\\ ±\sqrt{3}a\end{array}$

よって、 定数を a で表すと、

${a}^{3}-3a·3{a}^{2}=-8{a}^{3}$

コード

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

print('18, 19.')

class MyTestCase(TestCase):
def test18(self):
a, b = symbols('a, b', real=True)
s = solve(a ** 2 * (1 + I) - 2 * a * (b + I) + (3 - 8 * I))
self.assertEqual(s, [{a: -2, b: -Rational(7, 4)},
{a: 4, b: Rational(19, 8)}])

def test19(self):
a = symbols('a', real=True)
b = symbols('b', nonzero=True, real=True)
alpha = a + b * I
r, i = (alpha ** 3).as_real_imag()
bs = solve(i, b)
self.assertGreater(len(bs), 1)
for b0 in bs:
self.assertEqual(r.subs({b: b0}), -8 * a ** 3)

if __name__ == "__main__":
main()


% ./sample18.py -v
18, 19.
test18 (__main__.MyTestCase) ... ok
test19 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.352s

OK
%