2020年4月17日金曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第5章(連立方程式と高次方程式)、2(連立2次方程式)、問13の解答を求めてみる。


  1. 70 cm の針金を a cm と b cm の2つの部分に切るとする。

    a cm の針金で正方形のわくを作る。

    b cm の針金で 辺の比が1対2の 長方形のわくを作る。

    正方形の面積は

    a42

    長方形の面積は

    b2·13·b2·23=b218

    また、

    a+b=70

    正方形と長方形の面積が

    150cm2

    なので、

    a42+b218=150

    よって、 切り分けた針金の良さのそれぞれの長さを求めるには連立2元2次方程式

    0<a<70,0<b<70-a{a+b=70a42+b218=150

    の解を求めればいい。

    b=70-aa42+70-a218=150a216+a2-140a+490018=15024·32a216+a2-140a+490018=150·24·329a2+8a2-1120a+39200=2160017a2-1120a+17600=017a-440a-40=0{a=44017cmb=75017cm{a=40cmb=30cm

コード

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

print('13.')

x, y = symbols('x, y', positive=True)


class TestRightTriangleSides(TestCase):
    def test(self):
        s = solve([x + y - 70,
                   (x / 4) ** 2 + y ** 2 * 2 / (2 * 3 * 2 * 3) - 150])
        self.assertEqual(s, [{x: Rational(440, 17), y: Rational(750, 17)},
                             {x: 40, y: 30}])


f = 70 - x
p = plot(f,
         (x / 4) ** 2 + (f / 2) * Rational(1, 3) * f / 2 * Rational(2, 3),
         150,
         (x, 0, 70),
         ylim=(0, 180),
         legend=True,
         show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange', 'pink']

for i, s in enumerate(p):
    s.line_color = colors[i]

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

if __name__ == "__main__":
    main()

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

% ./sample13.py -v
13.
test (__main__.TestRightTriangleSides) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.252s

OK
%

0 コメント:

コメントを投稿