## 2020年2月27日木曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 解の係数の関係、2次式の因数分解 - 2つの解の和と積、式の変形

1. $\begin{array}{l}\alpha +\beta =-\frac{-4}{3}=\frac{4}{3}\\ \alpha \beta =\frac{5}{3}\\ {\left(\alpha -\beta \right)}^{2}\\ ={\left(\alpha +\beta \right)}^{2}-4\alpha \beta \\ =\frac{16}{9}-4·\frac{5}{3}\\ =\frac{16-60}{9}\\ =-\frac{44}{9}\end{array}$

2. $\begin{array}{l}{\alpha }^{3}+{\beta }^{3}\\ =\left(\alpha +\beta \right)\left({\alpha }^{2}-\alpha \beta +{\beta }^{2}\right)\\ =\left(\alpha +\beta \right)\left({\left(\alpha +\beta \right)}^{2}-3\alpha \beta \right)\\ ={\left(\alpha +\beta \right)}^{3}-3\alpha \beta \left(\alpha +\beta \right)\\ =\frac{64}{27}-5·\frac{4}{3}\\ =\frac{64-180}{27}\\ =-\frac{116}{27}\end{array}$

3. $\begin{array}{l}\frac{1}{\alpha }+\frac{1}{\beta }\\ =\frac{\alpha +\beta }{\alpha \beta }\\ =\frac{4}{3}·\frac{3}{5}\\ =\frac{4}{5}\end{array}$

4. $\begin{array}{l}\frac{\alpha -1}{{\alpha }^{2}}+\frac{\beta -1}{{\beta }^{2}}\\ =\frac{\left(\alpha -1\right){\beta }^{2}+{\alpha }^{2}\left(\beta -1\right)}{{\alpha }^{2}{\beta }^{2}}\\ =\frac{\alpha \beta \left(\alpha +\beta \right)-\left({\alpha }^{2}+{\beta }^{2}\right)}{{\alpha }^{2}{\beta }^{2}}\\ =\frac{\alpha \beta \left(\alpha +\beta \right)-\left({\left(\alpha +\beta \right)}^{2}-2\alpha \beta \right)}{{\left(\alpha \beta \right)}^{2}}\\ =\frac{9}{25}\left(\frac{5}{3}·\frac{4}{3}-\left(\frac{16}{9}-\frac{10}{3}\right)\right)\\ =\frac{9}{25}·\frac{20-16+30}{9}\\ =\frac{34}{25}\end{array}$

5. $\begin{array}{l}{\alpha }^{4}-{\alpha }^{2}{\beta }^{2}+{\beta }^{4}\\ ={\left({\alpha }^{2}+{\beta }^{2}\right)}^{2}-3{\alpha }^{2}{\beta }^{2}\\ ={\left({\left(\alpha +\beta \right)}^{2}-2\alpha \beta \right)}^{2}-3{\left(\alpha \beta \right)}^{2}\\ ={\left(\frac{16}{9}-\frac{10}{3}\right)}^{2}-3·\frac{25}{9}\\ ={\left(-\frac{14}{9}\right)}^{2}-\frac{75}{9}\\ =\frac{196}{81}-\frac{675}{81}\\ =-\frac{479}{81}\end{array}$

コード

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

print('24.')

x = symbols('x')
a, b = solve(3 * x ** 2 - 4 * x + 5)

class MyTestCase(TestCase):
def test1(self):
self.assertEqual((a - b) ** 2, -Rational(44, 9))

def test2(self):
self.assertEqual((a ** 3 + b ** 3).simplify(), -Rational(116, 27))

def test3(self):
self.assertEqual((1 / a + 1 / b).simplify(), Rational(4, 5))

def test4(self):
self.assertEqual(((a - 1) / a ** 2 + (b - 1) / b **
2).simplify(), Rational(34, 25))

def test5(self):
self.assertEqual((a ** 4 - a ** 2 * b ** 2 + b **
4).simplify(), -Rational(479, 81))

if __name__ == "__main__":
main()


% ./sample24.py -v
24.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok
test4 (__main__.MyTestCase) ... ok
test5 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 5 tests in 0.208s

OK
%