裏 RjpWiki

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

算額(その2028)

2024年08月18日 | Julia

算額(その2028)

(8) 兵庫県山崎町門前 八幡神社 明治3年(1870)
近畿数学史学会:近畿の算額「数学の絵馬を訪ねて」,平成4年5月16日 初版第一刷,大阪教育図書株式会社,大阪市.
キーワード:円8個,外円,弦2本

長方形の中に斜線2本をひき,黒円 2 個と赤円 1 個を容れる。
長方形の長辺と短辺の長さが 6 寸,4 寸,赤円の直径が 3 寸のとき,黒円の直径はいかほどか。

注:条件が 3 つ与えられているが,赤円の直径は黒円の直径を求めるのには何の役割も持たない。長方形の長辺と短辺の長さだけが与えられれば,黒円の直径も,赤円の直径も別々に求めることができる。

方形の長辺と短辺の長さを 2a, b
黒円の半径と中心座標を r1, (a - r1, r1)
赤円の半径と中心座標を r2, (0, b - r2)
とおき,以下の方程式を(別々に)解く。

1. 黒円の直径

include("julia-source.txt");

using SymPy

@syms a::positive, b::positive,
     r1::positive, r2::positive
eq1 = a + b - sqrt(a^2 + b^2) - 2r1
res1 = solve(eq1, r1)[1]
res1 |> println
res1(a => 6/2, b => 4) |> println

   a/2 + b/2 - sqrt(a^2 + b^2)/2
   1.00000000000000

長方形の長辺と短辺の長さが 6 寸,4 寸 のとき,黒円の直径は 2 寸である。

2. 赤円の直径

赤円の直径は「問」で与えられているが,長方形の長辺と短辺の長さから計算できる。

eq2 = r2/(b - r2) - a/sqrt(a^2 + b^2)
res2 = solve(eq2, r2)[1]
res2 |> println
res2(a => 6/2, b => 4) |> println

   a*b/(a + sqrt(a^2 + b^2))
   1.50000000000000

長方形の長辺と短辺の長さが 6 寸,4 寸 のとき,赤円の直径は(「問」で述べられている通り) 3 寸である。

function draw(a, b, more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r1 = a/2 + b/2 - sqrt(a^2 + b^2)/2
   r2 = a*b/(a + sqrt(a^2 + b^2))
   @printf("長方形の長辺と短辺の長さが %g,%g のとき,黒円の直径は %g,赤円の直径は %g である。\n", 2a, b, 2r1, 2r2)
   plot([a, a, -a, -a, a], [0, b, b, 0, 0], color=:green, lw=0.5)
   circle2(a - r1, r1, r1, :black)
   circle(0, b - r2, r2)
   plot!([-a, 0, a], [b, 0, b], color=:magenta, lw=0.5)
   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)", :black, :center, delta=-delta)
       point(0, b - r2, "赤円:r2,(0,b-r2)", :red, :center, delta=-delta)
       point(a, b, "(a,b)", :green, :right, :bottom, delta=delta)
   end
end;

draw(6/2, 4, true)

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

算額(その2027)

2024年08月18日 | Julia

算額(その2027)

(8) 兵庫県山崎町門前 八幡神社 明治3年(1870)
近畿数学史学会:近畿の算額「数学の絵馬を訪ねて」,平成4年5月16日 初版第一刷,大阪教育図書株式会社,大阪市.
キーワード:円8個,外円,弦2本

外円の中に,弦 2 本と黒円 3 個,赤円 4 個を容れる。黒円が 9 寸のとき,赤円の直径はいかほどか。

外円の半径と中心座標を R, (0, 0); R = 3r1
黒円の半径と中心座標を r1, (0, R - r1)
赤円の半径と中心座標を r2, (x2, R - 2r1 + r2)
とおき,以下の連立方程式を解く。

include("julia-source.txt");

using SymPy

@syms R::positive, r1::positive,
     r2::positive, x2::positive
R = 3r1
eq1 = x2^2 + (r1 - r2)^2 - (r1 + r2)^2
eq2 = x2^2 + (R - 2r1 + r2)^2 - (R - r2)^2
res = solve([eq1, eq2], (r2, x2))[1]

   (2*r1/3, 2*sqrt(6)*r1/3)

赤円の半径 r2 は,黒円の半径 r1 の 2/3 倍である。
黒円の直径が 9 寸のとき,赤円の直径は 6 寸である。

function draw(r1, more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   R = 3r1
   (r2, x2) = (2*r1/3, 2*sqrt(6)*r1/3)
   y = R - 2r1
   x = sqrt(R^2 - y^2)
   plot()
   circle(0, 0, R, :magenta)
   circle22(0, R - r1, r1)
   circle(0, 0, r1)
   circle4(x2, R - 2r1 + r2, r2, :blue)
   segment(-x, y, x, y, :green)
   segment(-x, -y, x, -y, :green)
   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(0, R - r1, "黒円:r1,(0,R-r1)", :red, :center, delta=-delta/2)
       point(x2, R - 2r1 + r2, "赤円:r2\n(x2,R-2r1+r2)", :blue, center, :bottom, delta=delta/2)
       point(0, R - 2r1, "R-2r1", :green, :center, delta=-delta)
       point(R, 0, " R", :magenta, :left, :bottom, delta=delta/2)
       point(0, R, " R", :magenta, :left, :bottom, delta=delta/2)
   end
end;

draw(9/2, true)

 

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

算額(その2026)

2024年08月18日 | Julia

算額(その2026)

(5) 兵庫県伊丹市寺本堂山 昆陽寺 嘉永7年(1854),昭和43年(1968)復元奉納
近畿数学史学会:近畿の算額「数学の絵馬を訪ねて」,平成4年5月16日 初版第一刷,大阪教育図書株式会社,大阪市.
キーワード:円8個,外円

外円の中に,甲円 2 個,乙円 2 個,丙円 2 個,丁円 1 個を容れる。丙円の直径が 与えられたとき,小円の直径を求めよ。

外円の半径と中心座標を R, (0, 0)
甲円の半径と中心座標を r1, (r1, y1)
乙円の半径と中心座標を r2, (x2, y2)
丙円の半径と中心座標を r3, (r3, y3)
丁円の半径と中心座標を r4, (0, 0)
とおき,以下の連立方程式を解く。

include("julia-source.txt");

using SymPy

@syms R::positive, r1::positive, y1::positive,
     r2::positive, x2::positive, y2::positive,
     r3::positive, y3::negaLtive, r4::positive, y4::positive
(r1, r3) = (3, 4)
eq1 = r1^2 + y1^2 - (R - r1)^2
eq2 = x2^2 + y2^2 - (R - r2)^2
eq3 = r3^2 + y3^2 - (R - r3)^2
eq4 = r1^2 + (y1 - y4)^2 - (r1 + r4)^2
eq5 = x2^2 + (y2 - y4)^2 - (r2 + r4)^2
eq6 = r3^2 + (y4 - y3)^2 - (r3 + r4)^2
eq7 = (x2 - r1)^2 + (y1 - y2)^2 - (r1 + r2)^2
eq8 = (x2 - r3)^2 + (y2 - y3)^2 - (r2 + r3)^2;

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)
   (R, y1, r2, x2, y2, y3, r4, y4) = u
   return [
       r1^2 + y1^2 - (R - r1)^2,  # eq1
       x2^2 + y2^2 - (R - r2)^2,  # eq2
       r3^2 + y3^2 - (R - r3)^2,  # eq3
       r1^2 - (r1 + r4)^2 + (y1 - y4)^2,  # eq4
       x2^2 - (r2 + r4)^2 + (y2 - y4)^2,  # eq5
       r3^2 - (r3 + r4)^2 + (-y3 + y4)^2,  # eq6
       (-r1 + x2)^2 - (r1 + r2)^2 + (y1 - y2)^2,  # eq7
       -(r2 + r3)^2 + (-r3 + x2)^2 + (y2 - y3)^2,  # eq8
   ]
end;
(r1, r3) = (3, 3.63)
(r1, r3) = (3, 4)
iniv = BigFloat[10, 6.3, 3.34, 6.58, 1.03, -5.25, 3.35, 0.65]
res = nls(H, ini=iniv)

   ([10.501127728389324, 6.875093977365777, 3.4285714285714284, 6.857142857142857, 1.732236834508634, -5.124906022634223, 3.452176679438275, 1.1627753673189665], true)

function draw(r1, r3, more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (R, y1, r2, x2, y2, y3, r4, y4) = res[1]
   plot()
   circle(0, 0, R, :orange)
   circle2(r1, y1, r1, :magenta)
   circle2(x2, y2, r2, :green)
   circle2(r3, y3, r3)
   circle(0, y4, r4, :blue)
   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(r1, y1, "甲円:r1,(r1,y1)", :magenta, :center, delta=-delta/2)
       point(x2, y2, "乙円:r2,(x2,y2)", :green, :center, delta=-delta/2)
       point(r3, y3, " 丙円:r3,(r3,y3)", :red, :center, delta=-delta/2)
       point(0, y4, "丁円:r4,(0,y4)", :blue, :center, delta=-delta/2)
       point(R, 0, " R", :orange, :left, :bottom, delta=delta/2)
       point(0, R, " R", :orange, :left, :bottom, delta=delta/2)
   end
end;

draw(6/2, 8/2, true)

コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

PVアクセスランキング にほんブログ村

PVアクセスランキング にほんブログ村