算額(その1247)
四十九 群馬県安中市板鼻 鷹巣神社 文政11年(1828)
群馬県和算研究会:群馬の算額,上武印刷株式会社,高崎市,1987年3月31日.
キーワード:円5個,長方形
長方形の中に,甲,乙,丙,丁,戊の 5 円を容れる。長方形の長辺が 38 寸のとき, 短辺はいかほどか。
長方形の長編,短辺を a, b
甲円の半径と中心座標を r1, (a - r1, r1)
乙円の半径と中心座標を r2, (r2, b - r2)
丙円の半径と中心座標を r3, (r3, r3)
丁円の半径と中心座標を r4, (x4, b - r4)
戊円の半径と中心座標を r5, (a - r5, b - r5)
とおき,以下の連立方程式を解く。
include("julia-source.txt");
using SymPy
@syms a::positive, b::positive, r1::positive, r2::positive,
r3::positive, r4::positive, x4::positive, r5::positive
@syms a, b, r1, r2, r3, r4, x4, r5
a = Sym(38)
eq1 = (a - r1 - r2)^2 + (b - r2 -r1)^2 - (r1 + r2)^2
eq2 = (a - r1 - r3)^2 + (r1 - r3)^2 - (r1 + r3)^2
eq3 = (a - r1 - x4)^2 + (r1 - b + r4)^2 - (r1 + r4)^2
eq4 = (r1 - r5)^2 + (b - r5 - r1)^2 - (r1 + r5)^2
eq5 = (r2 - r3)^2 + (b - r2 - r3)^2 - (r2 + r3)^2
eq6 = (x4 - r2)^2 + (r2 - r4)^2 - (r2 + r4)^2
eq7 = (a - r5 - x4)^2 + (r5 - r4)^2 - (r4 + r5)^2;
# res = solve([eq1, eq2, eq3, eq4, eq5, eq6, eq7], (b, r1, r2, r3, r4, x4, r5))
using NLsolve
function nls(func, params...; ini = [0.0])
if typeof(ini) <: Number
r = nlsolve((vout, vin) -> vout[1] = func(vin[1], params..., [ini]), ftol=big"1e-40")
v = r.zero[1]
else
r = nlsolve((vout, vin)->vout .= func(vin, params...), ini, ftol=big"1e-40")
v = r.zero
end
return Float64.(v), r.f_converged
end;
function H(u)
(b, r1, r2, r3, r4, x4, r5) = u
return [
-(r1 + r2)^2 + (a - r1 - r2)^2 + (b - r1 - r2)^2, # eq1
(r1 - r3)^2 - (r1 + r3)^2 + (a - r1 - r3)^2, # eq2
-(r1 + r4)^2 + (a - r1 - x4)^2 + (-b + r1 + r4)^2, # eq3
(r1 - r5)^2 - (r1 + r5)^2 + (b - r1 - r5)^2, # eq4
(r2 - r3)^2 - (r2 + r3)^2 + (b - r2 - r3)^2, # eq5
(-r2 + x4)^2 + (r2 - r4)^2 - (r2 + r4)^2, # eq6
(-r4 + r5)^2 - (r4 + r5)^2 + (a - r5 - x4)^2, # eq7
]
end;
a = 38
iniv = BigFloat[33, 12, 9, 7.5, 4.5, 23, 5.5]
res = nls(H, ini=iniv)
([33.00311463837703, 11.814579503859783, 9.106235741252021, 7.437509234825292, 4.897027068931824, 22.461906135655383, 5.325015237401601], true)
長方形の長辺が 38 寸のとき, 短辺は 33.00311463837703 寸である。
その他のパラメータは以下のとおりである。
a = 38; b = 33.0031; r1 = 11.8146; r2 = 9.10624; r3 = 7.43751; r4 = 4.89703; x4 = 22.4619; r5 = 5.32502
function draw(a, more=false)
pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
(b, r1, r2, r3, r4, x4, r5) = res[1]
@printf("a = %g; b = %g; r1 = %g; r2 = %g; r3 = %g; r4 = %g; x4 = %g; r5 = %g\n",
a, b, r1, r2, r3, r4, x4, r5)
plot([0, a, a, 0, 0], [0, 0, b, b, 0], color=:black, lw=0.5)
circle(a - r1, r1, r1)
circle(r2, b - r2, r2, :green)
circle(r3, r3, r3, :blue)
circle(x4, b - r4, r4, :magenta)
circle(a - r5, b - r5, r5, :orange)
if more
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)
point(a - r1, r1, "甲円:r1,(a-r1,r1)", :red, :center, delta=-delta)
point(r2, b - r2, "乙円:r2,(r2,b-r2)", :green, :center, delta=-delta)
point(r3, r3, "丙円:r3,(r3,r3)", :blue, :center, delta=-delta)
point(x4, b - r4, "丁円:r4\n(x4,b-r4)", :magenta, :center, delta=-delta)
point(a - r5, b - r5, "戊円:r5\n(a-r5,b-r5)", :orange, :center, delta=-delta)
point(a, b, "(a,b)", :black, :right, :bottom, delta=delta)
end
end;
draw(38, true)