## 2019年10月1日火曜日

### 数学 - Python - 急速・緩慢に変化する関係 - 指数関数・対数関数 - 対数関数の性質 - 常用対数 - 常用対数表、積の対数と対数の和

1. $\begin{array}{l}{\mathrm{log}}_{10}4.5\\ =0.6532\end{array}$

2. $\begin{array}{l}{\mathrm{log}}_{10}52.83\\ =1+{\mathrm{log}}_{10}5.283\\ =1.7228\end{array}$

3. $\begin{array}{l}{\mathrm{log}}_{10}600\\ =2+{\mathrm{log}}_{10}6\\ =2.7782\end{array}$

4. $\begin{array}{l}{\mathrm{log}}_{10}72.35\\ =1+{\mathrm{log}}_{10}7.235\\ =1.8594\end{array}$

5. $\begin{array}{l}{\mathrm{log}}_{10}0.325\\ =-1+0.5119\\ =-0.4881\end{array}$

6. $\begin{array}{l}{\mathrm{log}}_{10}0.4857\\ =-1+0.6863\\ =-0.3137\end{array}$

7. $\begin{array}{l}{\mathrm{log}}_{10}0.008098\\ =-3+{\mathrm{log}}_{10}8.098\\ =-3+0.9083\\ =-2.0917\end{array}$

コード

Python 3

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, log, plot
import math

print('29.')

spam = [4.5, 52.83, 600, 72.35, 0.325, 0.4857, 0.008098]
egg = [0.6532, 1.7228, 2.7782, 1.8594, -0.4881, -0.3137, -2.0917]

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

def tearDown(self):
pass

def test_math_log10(self):
for s, t in zip(spam, egg):
self.assertAlmostEqual(math.log10(s), t, places=3)

def test_sympy_log10(self):
for s, t in zip(spam, egg):
self.assertAlmostEqual(float(log(s, 10)), t, places=3)

if __name__ == '__main__':
x = symbols('x')
p = plot(log(x, 10),
(x, 0.1, 5.1),
ylim=(-2.5, 2.5),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for s, color in zip(p, colors):
s.line_color = color

p.show()
p.save(f'sample29.png')
main()


$./sample29.py -v 29. test_math_log10 (__main__.MyTestCase) ... ok test_sympy_log10 (__main__.MyTestCase) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.010s OK$