算額(その816)
文化三年丙寅正月 藤田貞資門人 石州津和野 二介泉尹
藤田貞資(1807):続神壁算法
http://www.wasan.jp/jinpeki/zokujinpekisanpo.pdf
直角三角形の田がある。直角を挟む二辺の短い方(鈎),長い方(股)が 6 間,8 間のとき,鈎,股に平行な直線で区切ってできる長方形(長辺(長),短辺(平)で,頂点の一つは斜辺上にある)の田の面積が最大になるとき,長,平はいかほどか。
鈎,股を A, B,鈎,股上にある点を a(平), b(長) とおくと,長方形の面積 S は S = a*b である。
以下の連立方程式を解く。
include("julia-source.txt");
# julia-source.txt ソース https://blog.goo.ne.jp/r-de-r/e/ad3a427b84bb416c4f5b73089ae813cf
using SymPy
@syms A, B, a, b, S
eq1 = (A - a)/b - A/B
eq2 = a/(B - b) - A/B
eq3 = a*b - S
res = solve([eq1, eq2, eq3], (a, b, S))
1-element Vector{Tuple{Sym{PyCall.PyObject}, Sym{PyCall.PyObject}, Sym{PyCall.PyObject}}}:
(A*(B - b)/B, b, A*b*(B - b)/B)
S = res[1][3]
S |> println
A*b*(B - b)/B
問のように,A = 6, B = 8 のとき,b の取り方で,面積 S は b の関数で,S(b) は以下のように変化する。
pyplot(size=(300, 150), grid=false, aspectratio=:none, label="", fontfamily="IPAMincho")
plot(S(A => 6, B => 8), xlims=(0, 8), xlabel="b", ylabel="S(b)")
面積が最大になるの上図の曲線の接線の傾きが 0 になるときである。数値的に解くには,S(b) を b で微分し,S'(b) = 0 になるときの b の値を求める。
diff(S, b) |> println
-A*b/B + A*(B - b)/B
solve(diff(S, b), b)[1] |> println
B/2
b = B/2,a = A/2 が解である。
すなわち,長方形の短辺が 3 間,長辺が 6 間である。
function draw(more)
pyplot(size=(300, 300), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
(A, B) = (6, 8)
(a, b) = (3, 4)
plot([0, B, 0, 0], [0, 0, A, 0])
rect(0, 0, b, a, :red)
if more == true
delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3 # size[2] * fontsize * 2
#hline!([0], color=:gray80, lw=0.5)
#vline!([0], color=:gray80, lw=0.5)
plot!(showaxis=false)
point(0, A, " A(鈎)", :blue, :left, :bottom, delta=delta/2)
point(B, 0, " B(股)", :blue, :left, :bottom, delta=delta/2)
point(0, a, " a(平)", :red, :left, :bottom, delta=delta/2)
point(b, 0, " b(長)", :red, :left, :bottom, delta=delta/2)
end
end;