数学のブログ

積分法 3直線で囲まれる図形の面積、定積分の計算

微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅣ.(積分法)、演習問題19.の解答を求めてみる。

y = - x + 1 y = x y = 1 2 x
- x + 1 = 1 2 x x = 2 3
- x + 1 = x x = 1 2

よって 求める図形の面積は、

0 1 2 ( x - 1 2 x ) dx + 1 2 2 3 ( ( - x + 1 ) - 1 2 x ) dx
= 1 2 0 1 2 x dx + 1 2 2 3 ( 1 - 3 2 x ) dx
= 1 2 · 1 2 · ( 1 2 ) 2 + ( 2 3 - 1 2 ) - 3 2 · 1 2 ( ( 2 3 ) 2 - ( 1 2 ) 2 )
= 1 16 + 1 6 - 3 4 ( 4 9 - 1 4 )
= 1 16 + 1 6 - 3 4 · 7 36
= 1 16 + 1 6 - 7 48
= 3 + 8 - 7 48
= 4 48
= 1 12

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Integral, Rational, solve, pprint, plot
from sympy.abc import x

print('19.')

y1 = 1 - x
y2 = x
y3 = x / 2
ys = [y1, y2, y3]
for yn in ys:
    for ym in ys:
        if yn != ym:
            pprint(solve(yn - ym, x))


class Test(TestCase):
    def test(self):
        self.assertEqual(
            Integral(x - x / 2, (x, 0, Rational(1, 2))).doit() +
            Integral(1 - 3 * x / 2, (x, Rational(1, 2), Rational(2, 3))).doit(),
            Rational(1, 12)
        )


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

p = plot(*ys, (x, 0, 1), legend=True, show=False)
for o, color in zip(p, colors):
    o.line_color = color
p.show()
p.save('sample19.png')


if __name__ == "__main__":
    main()

入出力結果

% ./sample19.py -v
19.
[1/2]
[2/3]
[1/2]
[0]
[2/3]
[0]
test (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.034s

OK
%