学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第4章(1次方程式, 2次方程式 )、5(解の係数の関係、2次式の因数分解)、問28の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, sqrt, plot, I, pprint
print('28.')
x = symbols('x', image=True)
abcs = [(56, 89, 35),
(3, 2, -4),
(24, -74, -35),
(3, -4, -2),
(9, 0, 25),
(1, -1, 1),
(2, -14 * sqrt(2), 13),
(sqrt(5), -sqrt(11), sqrt(5))]
fs = [a * x ** 2 + b * x + c for a, b, c in abcs]
gs = [(7 * x + 5) * (8 * x + 7),
3 * (x - (-1-sqrt(13)) / 3) * (x - (-1 + sqrt(13)) / 3),
(2 * x - 7) * (12 * x + 5),
3 * (x - (2 - sqrt(10)) / 3) * (x - (2 + sqrt(10)) / 3),
(3 * x - 5 * I) * (3 * x + 5 * I),
(x - (1 - sqrt(3) * I) / 2) * (x - (1 + sqrt(3) * I) / 2),
2 * (x - sqrt(2) / 2) * (x - 13 * sqrt(2) / 2),
sqrt(5) * (x - (sqrt(55) - 3 * sqrt(5) * I) / 10) *
(x - (sqrt(55) + 3 * sqrt(5) * I) / 10)
]
class MyTestCase(TestCase):
def test(self):
for i, (f, g) in enumerate(zip(fs, gs), 1):
print(f'({i})')
self.assertEqual(f, g.expand())
p = plot(*fs,
ylim=(-10, 10),
legend=False,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for i, s in enumerate(p):
s.line_color = colors[i]
for o in zip(p, colors):
pprint(o)
for i, f in enumerate(fs, 1):
print(f'({i})')
pprint(f.factor(gaussian=True))
p.show()
p.save('sample28.png')
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample28.py -v
28.
(cartesian line: 56*x**2 + 89*x + 35 for x over (-10.0, 10.0), red)
(cartesian line: 3*x**2 + 2*x - 4 for x over (-10.0, 10.0), green)
(cartesian line: 24*x**2 - 74*x - 35 for x over (-10.0, 10.0), blue)
(cartesian line: 3*x**2 - 4*x - 2 for x over (-10.0, 10.0), brown)
(cartesian line: 9*x**2 + 25 for x over (-10.0, 10.0), orange)
(cartesian line: x**2 - x + 1 for x over (-10.0, 10.0), purple)
(cartesian line: 2*x**2 - 14*sqrt(2)*x + 13 for x over (-10.0, 10.0), pink)
(cartesian line: sqrt(5)*x**2 - sqrt(11)*x + sqrt(5) for x over (-10.0, 10.0), g
ray)
(1)
56⋅(x + 5/7)⋅(x + 7/8)
(2)
⎛ 2 2⋅x 4⎞
3⋅⎜x + ─── - ─⎟
⎝ 3 3⎠
(3)
24⋅(x - 7/2)⋅(x + 5/12)
(4)
⎛ 2 4⋅x 2⎞
3⋅⎜x - ─── - ─⎟
⎝ 3 3⎠
(5)
⎛ 5⋅ⅈ⎞ ⎛ 5⋅ⅈ⎞
9⋅⎜x - ───⎟⋅⎜x + ───⎟
⎝ 3 ⎠ ⎝ 3 ⎠
(6)
2
x - x + 1
(7)
⎛ 2 13⎞
2⋅⎜x - 7⋅√2⋅x + ──⎟
⎝ 2 ⎠
(8)
2
√5⋅x - √11⋅x + √5
test (__main__.MyTestCase) ... (1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
ok
----------------------------------------------------------------------
Ran 1 test in 0.012s
OK
%
0 コメント:
コメントを投稿