2020年3月4日水曜日

学習環境

微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅣ.(積分法)、11.(平面図形の面積の計算)、問1、2.の解答を求めてみる。


  1. x 2 - x = 0 x x - 1 = 0 0 1 - x 2 - x dx = - 1 3 x 3 - x 2 0 1 = 1 - 1 3 = 2 3

  2. 0 x 1 λ 1 x - λ 2 x dx + x 1 x 2 f x - λ 2 x dx = λ 1 - λ 2 2 x 1 2 - λ 2 2 x 2 2 - x 1 2 + x 1 x 2 f x dx = 1 2 λ 1 x 1 2 - λ 2 x 2 2 + x 1 x 2 f x dx

コード

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

print('1, 2.')

x = symbols('x')
f = x ** 2 - x
g = - x ** 3 - 2 * x ** 2 + x + 10

lambda1 = 2
lambda2 = 1

l1 = lambda1 * x
l2 = lambda2 * x


class MyTestCase(TestCase):
    def test1(self):
        self.assertEqual(Integral(x - f, (x, 0, 1)).doit(), Rational(2, 3))


p = plot(f, g, l1, l2,
         (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(f'sample1.png')

if __name__ == '__main__':
    main()

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

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

----------------------------------------------------------------------
Ran 1 test in 0.022s

OK
%

0 コメント:

コメントを投稿