2020年2月11日火曜日

数学 - Python - 代数学 - 1次方程式, 2次方程式 - 複素数 - 四則演算(加減乗除)

1. $\begin{array}{l}{\left(4x+a\right)}^{2}\\ =16{x}^{2}+8ax+{a}^{2}\\ 8a=-72\\ a=-9\end{array}$

よって、

$16{x}^{2}-72x+81={\left(4x-9\right)}^{2}$

2. ${\left(\frac{1}{2}·\frac{1}{2}\right)}^{2}=\frac{1}{16}$

3. $\begin{array}{l}2\sqrt{9{y}^{2}}a=-24xy\\ 6ya=-24xy\\ a=-4x\\ 16{x}^{2}\end{array}$

4. ${\left(-\frac{1}{2}b·\frac{1}{2}\right)}^{2}=\frac{1}{4}{b}^{2}$

5. ${\left(\frac{5}{4}by\frac{1}{2}\right)}^{2}=\frac{25}{64}{b}^{2}{y}^{2}$

6. $\begin{array}{l}{\left(\frac{1}{2}·8\left(x-y\right)\right)}^{2}\\ =16{\left(x-y\right)}^{2}\end{array}$

7. $\begin{array}{l}2\sqrt{4{x}^{2}}\sqrt{25{y}^{2}}\\ =20xy\end{array}$

8. $\begin{array}{l}2\sqrt{\frac{1}{4}{\left(a+b\right)}^{2}{x}^{2}}\sqrt{9{y}^{4}}\\ =2·\frac{1}{2}\left(a+b\right)x·3{y}^{2}\\ =3\left(a+b\right)x{y}^{2}\end{array}$

コード

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

print('12.')

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

class MyTestCase(TestCase):
def test(self):
exprs = [(5 - 3 * I) - (5 + 2 * I),
(4 - 2 * I) - (3 + 5 * I) + (11 - 9 * I),
(6 * I) ** 2,
(4 + 5 * I) * (3 - 2 * I),
(3 + 5 * I) ** 2 + (1 + 4 * I) ** 2,
2 * I * 4 * I * (-3 * I / 4),
5 / (3 - 4 * I),
(1 - I) / (1 + I),
(1 + sqrt(2) * I) ** 3,
I ** 5,
(1 - I) ** 4,
1 / (4 * I),
(2 - sqrt(3) * I) / (2 + sqrt(3) * I),
(sqrt(3) + sqrt(2) * I) / (sqrt(3) -
sqrt(2) * I) * (1 - 2 * I) / (1 + I),
(-2 * I) ** 6,
((2 + I) / (3 - 2 * I)) ** 2]
zs = [(0, -5),
(12, -16),
(-36, 0),
(22, 7),
(-31, 38),
(0, 6),
(Rational(3, 5), Rational(4, 5)),
(0, -1),
(-5, sqrt(2)),
(0, 1),
(-4, 0),
(0, -Rational(1, 4)),
(Rational(1, 7), -4 * sqrt(3) / 7),
((6 * sqrt(6) - 1) / 10, -(3 + 2 * sqrt(6)) / 10),
(-64, 0),
(-Rational(33, 169), Rational(56, 169))]
for i, (expr, (a, b)) in enumerate(zip(exprs, zs), 1):
print(i)
self.assertEqual((expr - (a + b * I)).simplify(), 0)

if __name__ == "__main__":
main()


% ./sample12.py -v
12.
test (__main__.MyTestCase) ... 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ok

----------------------------------------------------------------------
Ran 1 test in 1.784s

OK
%