裏 RjpWiki

Julia ときどき R, Python によるコンピュータプログラム,コンピュータ・サイエンス,統計学

算額(その900)

2024年04月30日 | Julia

算額(その900)

七四 加須市大字外野 棘脱地蔵堂 明治7年(1874)埼玉県立図書館:埼玉県史料集 第二集『埼玉の算額』,昭和44年,誠美堂印刷所,埼玉県与野市.

外円の中に正三角形と大円,小円をそれぞれ 2 個ずつ入れる。外円の直径が 3 寸のとき小円の直径はいかほどか。

算額(その899)にもう一種類の円を加えたものであるが,SymPy の性能では数式解を求めることができない。

外円の半径と中心座標を R, (0, 0)
大円の半径と中心座標を r1, (R - r1, 0)
小円の半径と中心座標を r2, (x2, y2)
とおき,以下の連立方程式を解く。

include("julia-source.txt");

using SymPy
@syms R::positive, r1::positive, r2::positive, x2::positive, y2::positive
eq1 = (R - r1)cosd(Sym(30)) - r1
eq2 = x2^2 + y2^2 - (R - r2)^2
eq3 = (x2 - R + r1)^2 + y2^2 - (r1 + r2)^2
eq4 = dist2(0, 0, R*cosd(Sym(60)), R*sind(Sym(60)), x2, y2, r2);

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)
   (r1, r2, x2, y2) = u
   return [
       -r1 + sqrt(3)*(R - r1)/2,  # eq1
       x2^2 + y2^2 - (R - r2)^2,  # eq2
       y2^2 - (r1 + r2)^2 + (-R + r1 + x2)^2,  # eq3
       -r2^2 + 3*x2^2/4 - sqrt(3)*x2*y2/2 + y2^2/4,  # eq4
   ]
end;

R = 3/2
iniv = BigFloat[0.7, 0.24, 0.83, 0.95]
res = nls(H, ini=iniv)

   ([0.6961524227066319, 0.2460188097551155, 0.8278641121314027, 0.9418650844642568], true)

外円の直径が 3 寸のとき,小円の直径は 0.492037619510231 寸である。

その他のパラメータは以下のとおりである。
R = 1.5; r1 = 0.696152;  r2 = 0.246019;  x2 = 0.827864;  y2 = 0.941865;  x = 0.75;  y = 1.29904

算額の「答」,「術」ともに不適切であろう。

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   R = 3/2
   (r1, r2, x2, y2) = res[1]
   (x, y) = R .* (cosd(60), sind(60))
   @printf("外円の直径が %g のとき,小円の直径は %.15g である。\n", 2R, 2r2)
   @printf("R = %g; r1 = %g;  r2 = %g;  x2 = %g;  y2 = %g;  x = %g;  y = %g\n", R, r1, r2, x2, y2, x, y)
   plot([x, -x, x, -x, x], [y, y, -y, -y, y], color=:blue, lw=0.5)
   circle(0, 0, R, :green)
   circle2(R - r1, 0, r1, :magenta)
   circle4(x2, y2, r2)
   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(R, 0, " R", :blue, :left, :bottom, delta=delta/2)
       point(0, R, " R", :blue, :left, :bottom, delta=delta/2)
       point(R - r1, 0, "大円:r1,(0,R-r1)", :magenta, :center, delta=-delta)
       point(x2, y2, "小円:r2,(x2,y2)", :black, :center, delta=-delta)
       point(x, y, "(x,y)", :blue, :left, :bottom, delta=delta)
   end
end;


コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« 算額(その899) | トップ | 算額(その901) »
最新の画像もっと見る

コメントを投稿

Julia」カテゴリの最新記事