2020年6月6日土曜日

学習環境

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


  1. 直角をはさむ2辺のうちの1つの長さを x とすると、 2辺の長さは

    x , 10 - x 0 < x < 10

    よって、 直角三角形 の面積は

    1 2 x 10 - x = - 1 2 x 2 - 10 x = - 1 2 x - 5 2 + 25 2

    よって、2辺 の長さが 5、すなわち直角二等辺三角形のときの面稙は最大となり、 その値は

    25 2

コード

#!/usr/bin/env python3
import matplotlib.pyplot as plt
from matplotlib import animation
from sympy import symbols, plot, Rational

print('19.')

a = 10
x = symbols('x')
s = (a - x) * x / 2
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

p = plot(s, Rational(25, 2),
         (x, 0, 15),
         ylim=(0, 15),
         legend=True,
         show=False)
for o, color in zip(p, colors):
    o.line_color = color
p.save('sample19.png')
p.show()


def update_poly(i, poly: plt.Polygon):
    poly.set_xy([(0, 0), (0, a - 0.2 * i), (10 - a + 0.2 * i, 0)])
    return poly


fig = plt.gcf()
ax = plt.axes(xlim=(0, a), ylim=(0, a), aspect='equal')
poly = plt.Polygon([(0, 0), (0, a), ((10 - a), 0)])
ax.add_patch(poly)

anim = animation.FuncAnimation(fig, update_poly,
                               fargs=(poly,),
                               frames=50,
                               interval=100,
                               repeat=True)
plt.show()
anim.save('sample19.gif', writer='imagemagick')

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

% ./sample19.py
19.
%

0 コメント:

コメントを投稿