学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第4章(1次方程式, 2次方程式 )、3(複素数)の問12の解答を求めてみる。
よって、
コード
#!/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()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./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
%
0 コメント:
コメントを投稿