学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第5章(連立方程式と高次方程式)、3(因数定理)、問15、16の解答を求めてみる。
とおく。
とおく。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Rational, plot
print('15, 16.')
x = symbols('x')
f = x ** 3 + 2 * x ** 2 - 3 * x - 10
g = 4 * x ** 3 - 3 * x ** 2 + x + 1
class TestFactorTheorem(TestCase):
def test_15(self):
xs = [1, -1, 2, -3]
rs = [-10, -6, 0, -10]
for x0, r in zip(xs, rs):
self.assertEqual(f.subs({x: x0}), r)
def test_16(self):
xs = [Rational(1, 2), -Rational(1, 2), Rational(3, 2)]
rs = [Rational(5, 4), -Rational(3, 4), Rational(37, 4)]
for x0, r in zip(xs, rs):
self.assertEqual(g.subs({x: x0}), r)
p = plot(f, g,
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('sample15.png')
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample15.py -v
15, 16.
test_15 (__main__.TestFactorTheorem) ... ok
test_16 (__main__.TestFactorTheorem) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.006s
OK
%
0 コメント:
コメントを投稿