2020年3月4日水曜日

学習環境

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



    1. -1±1+484=-1±74=-2,32

      よって、

      2x+2yx-32y=x+2y2x-3y

    2. 7±49-366=7±1363x-7-136yx-7+136y

    3. -1±1-42=-1±3i2x--1-3i2yx--1+3i2y

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, sqrt, I, pprint
from sympy.plotting import plot3d

print('30.')

x, y = symbols('x, y')

abcs = [(2, 1, -6),
        (3, -7, 3),
        (1, 1, 1)]
fs = [a * x ** 2 + b * x * y + c * y ** 2 for a, b, c in abcs]


class MyTestCase(TestCase):
    def test(self):

        facts = [(x + 2 * y) * (2 * x - 3 * y),
                 3 * (x - (7 - sqrt(13)) / 6 * y) *
                 (x - (7 + sqrt(13)) / 6 * y),
                 (x - (-1 - sqrt(3) * I) / 2 * y) * (x - (- 1 + sqrt(3) * I) / 2 * y)]
        for i, (f, fact) in enumerate(zip(fs, facts), 1):
            print(f'({i})')
            self.assertEqual(f, fact.expand())


p = plot3d(*fs,
           show=False,
           xlabel=x,
           ylabel=y)

p.show()
p.save('sample30.png')

if __name__ == "__main__":
    main()

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

% ./sample30.py
30.
(1)
(2)
(3)
.
----------------------------------------------------------------------
Ran 1 test in 0.025s

OK
%

0 コメント:

コメントを投稿