## 2020年2月9日日曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 2次方程式 - 解の公式(根の公式)

1. $\begin{array}{l}x=\frac{5±\sqrt{25+96}}{12}\\ =\frac{5±\sqrt{121}}{12}\\ =\frac{5±11}{12}\\ =-\frac{1}{2},\frac{4}{3}\end{array}$

2. $\begin{array}{l}x=\frac{-2±\sqrt{{2}^{2}+4·4}}{2}\\ =-1±\sqrt{1+4}\\ =-1±\sqrt{5}\end{array}$

3. $\begin{array}{l}x=\frac{-8±\sqrt{{8}^{2}+4·16}}{2}\\ =-4±\sqrt{16+16}\\ =-4±4\sqrt{2}\end{array}$

4. $\begin{array}{l}x=\frac{-17±\sqrt{1{7}^{2}-24·12}}{2·6}\\ =\frac{-17±1}{12}\\ =-\frac{3}{2},-\frac{4}{3}\end{array}$

5. $\begin{array}{l}x=\frac{11±\sqrt{121-76}}{2}\\ =\frac{11±\sqrt{45}}{2}\\ =\frac{11±3\sqrt{5}}{2}\end{array}$

6. $\begin{array}{l}x=\frac{4±\sqrt{{4}^{2}+4·6}}{2·3}\\ =\frac{2±\sqrt{4+6}}{3}\\ =\frac{2±\sqrt{10}}{3}\end{array}$

7. $\begin{array}{l}25{x}^{2}-10x+1=0\\ x=\frac{10±\sqrt{4·{5}^{2}-4·25}}{2·25}\\ =\frac{2}{25}\\ =\frac{1}{5}\end{array}$

8. $\begin{array}{l}x=\frac{22±\sqrt{{2}^{2}·1{1}^{2}-4·49}}{2}\\ =11±\sqrt{121-49}\\ =11±\sqrt{72}\\ =11±6\sqrt{2}\end{array}$

9. $\begin{array}{l}x=\frac{-7±\sqrt{49+4·18}}{2·3\sqrt{2}}\\ =\frac{-7±\sqrt{49+72}}{6\sqrt{2}}\\ =\frac{-7±\sqrt{121}}{6\sqrt{2}}\\ =\frac{-7±11}{6\sqrt{2}}\\ =-\frac{3}{\sqrt{2}},\frac{2}{3\sqrt{2}}\\ =-\frac{3}{\sqrt{2}},\frac{\sqrt{2}}{3}\end{array}$

10. $\begin{array}{l}x=\frac{2·7\sqrt{3}±\sqrt{{2}^{2}·{7}^{2}·3-4·26}}{2·2}\\ =\frac{7\sqrt{3}±\sqrt{147-26}}{2}\\ =\frac{7\sqrt{3}±\sqrt{121}}{2}\\ =\frac{7\sqrt{3}±11}{2}\end{array}$

コード

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

print('10.')

class MyTestCase(TestCase):
def test(self):
x = symbols('x', real=True)
eqs = [(6, -5, -4),
(1, 2, -4),
(1, 8, -16),
(6, 17, 12),
(1, -11, 19),
(3, -4, -2),
(5, -2, Rational(1, 5)),
(1, -22, 49),
(3 * sqrt(2), 7, -3 * sqrt(2)),
(2, -14 * sqrt(3), 13)]
xss = [{-Rational(1, 2), Rational(4, 3)},
{-1 - sqrt(5), -1 + sqrt(5)},
{-4 - 4 * sqrt(2), -4 + 4 * sqrt(2)},
{-Rational(3, 2), -Rational(4, 3)},
{(11 - 3 * sqrt(5)) / 2, (11 + 3 * sqrt(5)) / 2},
{(2 - sqrt(10)) / 3, (2 + sqrt(10)) / 3},
{Rational(1, 5)},
{11 - 6 * sqrt(2), 11 + 6 * sqrt(2)},
{-3 / sqrt(2), sqrt(2) / 3},
{(7 * sqrt(3) - 11) / 2, (7 * sqrt(3) + 11) / 2}]
for (a, b, c), xs in zip(eqs, xss):
eq = a * x ** 2 + b * x + c
self.assertEqual(solveset(eq), xs)

if __name__ == "__main__":
main()


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

----------------------------------------------------------------------
Ran 1 test in 0.599s

OK
%