2020年2月13日木曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第4章(1次方程式, 2次方程式 )、3(複素数)の問14の解答を求めてみる。


  1.  
    x = 3 + 2 i 1 - i = 3 + 2 i 1 + i 2 = 1 + 5 i 2 x 2 = - 24 + 10 i 4 = - 12 + 5 i 2 x 3 + 2 x 2 + 3 x + 4 = 1 + 5 i 2 3 + 2 1 + 5 i 2 2 + 3 · 1 + 5 i 2 + 4 = - 12 + 5 i 2 · 1 + 5 i 2 - 12 + 5 i + 3 + 15 i 2 + 4 = - 37 - 55 i 4 - 8 + 5 i + 3 + 15 i 2 = - 63 - 5 i 4

コード

#!/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()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

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

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

OK
%

0 コメント:

コメントを投稿