学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第4章(1次方程式, 2次方程式 )、5(解の係数の関係、2次式の因数分解)、問30の解答を求めてみる。
よって、
コード
#!/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 コメント:
コメントを投稿