2020年5月16日土曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第5章(連立方程式と高次方程式) 、問10の解答を求めてみる。


  1. 2 x 2 - 3 x - 5 = x + 1 2 x - 5 { - 4 + a - b - 25 = 0 4 · 5 2 3 + 5 2 2 a + 5 2 b - 25 = 0 a - b = 29 5 3 2 + 5 2 2 2 a + 5 2 b - 25 = 0 2 · 5 2 + 5 a + 2 b - 20 = 0 5 a + 2 b = - 30 2 a - 2 b = 58 7 a = 28 a = 4 b = - 25

コード

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

print('10.')


class TestRemainder(TestCase):
    def test(self):
        x = symbols('x')
        a = 4
        b = -25
        f = 4 * x ** 3 + a * x ** 2 + b * x - 25
        self.assertEqual(2 * x ** 2 - 3 * x - 5,
                         ((x + 1) * (2 * x - 5)).expand())
        self.assertTrue(f.subs({x: -1}) == 0 and
                        f.subs({x: Rational(5, 2)}) == 0)


if __name__ == "__main__":
    main()

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

% ./sample10.py -v
10.
test (__main__.TestRemainder) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.041s

OK
%

0 コメント:

コメントを投稿