2020年1月10日金曜日

学習環境

解析入門(上) (松坂和夫 数学入門シリーズ 4) (松坂 和夫(著)、岩波書店)の第8章(積分の計算)、8.2(定積分の計算)、問題2の解答を求めてみる。


  1. a b f x dx = a 0 f x dx + 0 p f x dx + p b f x dx = - 0 a f x dx + 0 p f x dx + p a + p f x dx = 0 p f x dx - 0 a f x dx + 0 a f x dx = 0 p f x dx

    (証明終)

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sin, cos, pi, Integral, plot

print('2.')

x = symbols('x')
f = sin(x)
g = cos(x)
t = 2 * pi
a = symbols('a')
b = a + t


class MyTestCase(TestCase):
    def test_sin(self):
        self.assertEqual(Integral(f, (x, a, b)).doit(),
                         Integral(f, (x, 0, t)).doit())

    def test_cos(self):
        self.assertEqual(Integral(g, (x, a, b)).doit(),
                         Integral(g, (x, 0, t)).doit())


p = plot(f, g,
         (x, -5, 5),
         ylim=(-5, 5),
         legend=True,
         show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

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

p.show()
p.save('sample2.png')


if __name__ == '__main__':
    main()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample2.py -v
2.
test_cos (__main__.MyTestCase) ... ok
test_sin (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.049s

OK
%

0 コメント:

コメントを投稿