2020年2月4日火曜日

学習環境

微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅣ.(積分法)、5.(連続関数の原始関数)、問1、2.の解答を求めてみる。


  1. 02xdx=23x3202=23·232=423

  2. 図形

    AA'B'OBA

    の面積。

    2a3--aax2dx=2a3-20ax2dx=2a3-13x30a=2a3-13a3=43a3

    三角形

    AOA'

    の面積。

    2a·a22=a3

    よって、求める比は、

    43

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Integral, sqrt, plot, Rational

print('1, 2.')

x = symbols('x', real=True)
a = symbols('a', positive=True)
f = sqrt(x)
g = x ** 2


class MyTestCase(TestCase):
    def test1(self):
        self.assertEqual(Integral(f, (x, 0, 2)).doit(), 4 * sqrt(2) / 3)

    def test2(self):
        self.assertEqual((2 * a ** 3 - Integral(g, (x, -1 * a, a)).doit()) / a ** 3,
                         Rational(4, 3))


a0 = 2
p = plot(f, g.subs({a: a0}),
         - a0 * x, a0 * x, g.subs({x: a0}),
         (x, -2, 2),
         ylim=(0, 4),
         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(f'sample1.png')

if __name__ == '__main__':
    main()

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

% ./sample1.py -v
1, 2.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.129s

OK
%

0 コメント:

コメントを投稿