2019年12月29日日曜日

学習環境

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



    1. dx a 2 cos 2 x + b 2 sin 2 x = 1 cos 2 x a 2 + b 2 sin 2 x cos 2 x d x

      置換積分法。

      t = tan x

      とおくと、

      dt dx = 1 cos 2 x 1 a 2 + b 2 t 2 dt = 1 a 2 dt 1 + b a t 2 = 1 a 2 · a b arctan b a t = 1 a b arctan b a tan x

    2. dx a 2 cos 2 x - b 2 sin 2 x = dt a 2 - b 2 t 2 = dt a + b t a - b t A a + b t + B a - b t = A + B a + b B - A t a 2 - b 2 t 2 A + B = 1 a - A + B = 0 2 B = 1 a B = 1 2 a A = 1 2 a 1 2 a dt a + b t dt + 1 2 a dt a - b t = 1 2 a 1 b log a + b t - 1 b log a - b t = 1 2 a b log a + b t a - b t = 1 2 a b log a + b tan x a - b tan x = 1 2 a b log a cos x + b sin x a cos x - b sin x

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, Derivative, sin, cos, tan, atan, log, plot

print('6.')

a, b = symbols('a, b', nonzero=True)
x = symbols('x')
fs = [1 / (a ** 2 * cos(x) ** 2 + b ** 2 * sin(x) ** 2),
      1 / (a ** 2 * cos(x) ** 2 - b ** 2 * sin(x) ** 2)]
gs = [atan(b * tan(x) / a) / (a * b),
      log(abs((a * cos(x) + b * sin(x)) / (a * cos(x) - b * sin(x)))) / (2 * a * b)]

d = {a: 1, b: 2, x: 1}


class MyTestCase(TestCase):
    def test1(self):
        self.assertEqual(float(fs[0].subs(d)), float(
            Derivative(gs[0], x, 1).doit().subs(d)))


p = plot(*[f.subs({a: 1, b: 2}) for f in fs + gs],
         (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('sample6.png')


if __name__ == '__main__':
    main()

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

\% ./sample6.py -v
6.
test1 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.025s

OK
%

0 コメント:

コメントを投稿