学習環境
- Surface、Surface ペン(端末)
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad Pro 10.5 + Apple Pencil
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
新装版 数学読本2 (松坂 和夫(著)、岩波書店)の第7章(急速・緩慢に変化する関係 - 指数関数・対数関数)、7.3(対数関数の性質)、常用対数の問29の解答を求めてみる。
コード
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()
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
$ ./sample29.py -v 29. test_math_log10 (__main__.MyTestCase) ... ok test_sympy_log10 (__main__.MyTestCase) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.010s OK $
0 コメント:
コメントを投稿