## 2019年10月4日金曜日

### 数学 - Python - 代数学 - 実数 - 平方根を含む式の計算 - 分母の有理化

1. $\begin{array}{l}\frac{1}{\sqrt{28}}\\ =\frac{1}{2\sqrt{7}}\\ =\frac{\sqrt{7}}{14}\end{array}$

2. $\begin{array}{l}\frac{5}{4\sqrt{5}}\\ =\frac{\sqrt{5}}{4}\end{array}$

3. $\begin{array}{l}\frac{\sqrt{2}}{3-\sqrt{2}}\\ =\frac{\sqrt{2}\left(3+\sqrt{2}\right)}{9-2}\\ =\frac{3\sqrt{2}+2}{7}\end{array}$

4. $\begin{array}{l}\frac{3+\sqrt{2}}{1+\sqrt{2}}\\ =\frac{\left(3+\sqrt{2}\right)\left(1-\sqrt{2}\right)}{1-2}\\ =-\left(1-2\sqrt{2}\right)\\ =2\sqrt{2}-1\end{array}$

5. $\begin{array}{l}\frac{\sqrt{3}+\sqrt{5}}{\sqrt{3}-\sqrt{5}}\\ =\frac{8+2\sqrt{15}}{3-5}\\ =-4-\sqrt{15}\end{array}$

6. $\begin{array}{l}\frac{\sqrt{5}+2}{\left(\sqrt{3}-\sqrt{2}\right)\left(\sqrt{5}-2\right)}\\ =\frac{9+4\sqrt{5}}{\left(\sqrt{3}-\sqrt{2}\right)\left(5-4\right)}\\ =\left(9+4\sqrt{5}\right)\left(\sqrt{3}+\sqrt{2}\right)\\ =9\sqrt{3}+9\sqrt{2}+4\sqrt{15}+4\sqrt{10}\end{array}$

コード

Python 3

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

print('16.')

class MyTest(TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test(self):
spam = [1 / sqrt(28),
5 / (4 * sqrt(5)),
sqrt(2) / (3 - sqrt(2)),
(3 + sqrt(2)) / (1 + sqrt(2)),
(sqrt(3) + sqrt(5)) / (sqrt(3) - sqrt(5)),
(sqrt(5) + 2) / ((sqrt(3) - sqrt(2)) * (sqrt(5) - 2))]
egg = [sqrt(7)/14,
sqrt(5) / 4,
(3 * sqrt(2) + 2) / 7,
2 * sqrt(2) - 1,
-4 - sqrt(15),
9 * sqrt(3) + 9 * sqrt(2) + 4 * sqrt(15) + 4*sqrt(10)]
for i, (s, t) in enumerate(zip(spam, egg)):
print(i + 1)
self.assertEqual(float(s), float(t))

if __name__ == '__main__':
main()


$./sample15.py 15. . ---------------------------------------------------------------------- Ran 1 test in 0.294s OK$