算額(その572)
群馬の算額 19-2 榛名神社 文化8年
http://takasakiwasan.web.fc2.com/gunnsann/g019-2.html
正方形の中に 3 本の斜線を引き,区画された領域に大円,中円,小円を入れる。正方形の一辺の長さが 3 寸のとき,大円の直径を求めよ。
正方形の一辺の長さを a とする。
大円の半径と中心座標を r1, (r1, a - r1)
中円の半径と中心座標を r2, (a - r2, r2)
小円の半径と中心座標を r3, (r3, r3), (a - r3, a - r3)
とおき,以下の連立方程式を解く。
include("julia-source.txt");
using SymPy
@syms a::positive, r1::positive, r2::positive, r3::positive,
b::positive, c::positive, d::positive, e::positive
eq1 = distance(d, 0, 0, e, r1, a - r1) - r1^2 |> expand |> simplify |> numerator
eq2 = distance(d, 0, 0, e, a - r2, r2) - r2^2 |> expand |> simplify |> numerator
eq3 = distance(d, 0, 0, e, r3, r3) - r3^2 |> expand |> simplify |> numerator
eq4 = distance(b, 0, a, c, r1, a - r1) -r1^2 |> expand |> simplify |> numerator
eq5 = distance(b, 0, a, c, a - r2, r2) -r2^2 |> expand |> simplify |> numerator
eq6 = distance(b, 0, a, c, r3, r3) -r3^2 |> expand |> simplify |> numerator
eq7 = distance(b, 0, a, c, a - r3, a - r3) -r3^2 |> expand |> simplify |> numerator;
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 v, r.f_converged
end;
function H(u)
(r1, r2, r3, b, c, d, e) = u
return [
a^2*d - 2*a*d*e - 2*a*d*r1 + 2*a*e*r1 + d*e^2 + 2*d*e*r1 - 2*e^2*r1 - 2*e*r1^2, # eq1
a^2*e - 2*a*d*e + 2*a*d*r2 - 2*a*e*r2 + d^2*e - 2*d^2*r2 + 2*d*e*r2 - 2*d*r2^2, # eq2
d*e - 2*d*r3 - 2*e*r3 + 2*r3^2, # eq3
a^4 - 2*a^3*b - 2*a^3*r1 + a^2*b^2 + 2*a^2*b*c + 4*a^2*b*r1 - 2*a^2*c*r1 - 2*a*b^2*c - 2*a*b^2*r1 + 2*a*c*r1^2 + b^2*c^2 + 2*b^2*c*r1 - 2*b*c^2*r1 - 2*b*c*r1^2, # eq4
a^2*c - 2*a^2*r2 - 2*a*b*c + 4*a*b*r2 - 2*a*c*r2 + 2*a*r2^2 + b^2*c - 2*b^2*r2 + 2*b*c*r2 - 2*b*r2^2, # eq5
2*a*b*r3 - 2*a*r3^2 + b^2*c - 2*b^2*r3 - 2*b*c*r3 + 2*b*r3^2, # eq6
a^4 - 2*a^3*b - 2*a^3*c - 2*a^3*r3 + a^2*b^2 + 4*a^2*b*c + 4*a^2*b*r3 + a^2*c^2 + 4*a^2*c*r3 - 2*a*b^2*c - 2*a*b^2*r3 - 2*a*b*c^2 - 6*a*b*c*r3 - 2*a*c^2*r3 - 2*a*c*r3^2 + b^2*c^2 + 2*b^2*c*r3 + 2*b*c^2*r3 + 2*b*c*r3^2, # eq7
]
end;
a = 3
iniv = BigFloat[1.05, 0.7, 0.48, 0.7, 2.5, 2.0, 1.4]
res = nls(H, ini=iniv)
(BigFloat[1.074953912118040074148850906669271748631882063090927359480694112255763934484609, 0.6824054007626747794460829207016340156591023107782284209892666737724326939646588, 0.4738479700017459009683547528030295288720148655840843288085599668979468150150135, 0.670122225679428548319738745786848395358404741740433798054273686137994090593031, 2.329877774320571451680261254213151604641595258259566201945726313849903192359496, 2.121320343559642573202533086314547117854507813065422109765019606987497365607011, 1.330325847824819753801482812391145847210905426272977123802622116991951746211069], true)
大円の直径は 2.14991 寸である。
その他のパラメータは以下の通り。
r1 = 1.07495; r2 = 0.682405; r3 = 0.473848; b = 0.670122; c = 2.32988; d = 2.12132; e = 1.33033
function draw(more=false)
pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
(r1, r2, r3, b, c, d, e) = [1.05, 0.7, 0.48, 0.7, 2.5, 2.0, 1.4]
(r1, r2, r3, b, c, d, e) = res[1]
@printf("大円の直径 = %g; r1 = %g; r2 = %g; r3 = %g; b = %g; c = %g; d = %g; e = %g\n",
2r1, r1, r2, r3, b, c, d, e)
plot([0, a, a, 0, 0], [0, 0, a, a, 0], color=:blue, lw=0.5)
circle(r1, a - r1, r1)
circle(a - r2, r2, r2, :green)
circle(r3, r3, r3, :magenta)
circle(a - r3, a - r3, r3, :magenta)
segment(b, 0, a, c)
segment(d, 0, 0, e)
segment(a, a - d, a - e, a)
if more
delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3 # size[2] * fontsize * 2
hline!([0], color=:black, lw=0.5)
vline!([0], color=:black, lw=0.5)
point(b, 0, "b ", :black, :right, delta=3delta)
point(d, 0, "d", :black, :left, delta=3delta)
point(a, 0, "a ", :black, :right, delta=3delta)
point(0, e, " e", :black, :left, delta=2delta)
point(a, c, "(a,c) ", :black, :right, :vcenter)
point(a, a - d, "(a,a-d) ", :black, :right, :vcenter)
point(a - e, a, "(a-e,a)", :black, :center, :bottom, delta=delta/2)
point(0, a, " a", :black, :left, :bottom, delta=delta/2)
point(r1, a - r1, "大円:r1,(r1,a-r1)", :red, :center, delta=-delta/2)
point(a - r2, r2, "中円:r2,(a-r2,r2)", :green, :center, delta=-delta/2)
point(r3, r3, "小円:r3,(r3,r3)", :magenta, :center, delta=-delta/2)
point(a - r3, a - r3, "小円:r3,(a-r3,a-r3)", :magenta, :center, delta=-delta/2)
end
end;