2020年2月13日木曜日

学習環境

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


  1.  
    x=3+2i1-i=3+2i1+i2=1+5i2x2=-24+10i4=-12+5i2x3+2x2+3x+4=1+5i23+21+5i22+3·1+5i2+4=-12+5i2·1+5i2-12+5i+3+15i2+4=-37-55i4-8+5i+3+15i2=-63-5i4

コード

#!/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 コメント:

コメントを投稿