裏 RjpWiki

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

算額(その632)

2024年01月11日 | Julia

算額(その632)

和算図形問題あれこれ
令和3年11月の問題2

https://gunmawasan.web.fc2.com/kongetu-no-mondai.html

直角三角形の中に,正三角形と等円 2 個を入れる。股の長さが 487 寸のとき,正三角形の一辺の長さはいかほどか。

正三角形の一辺の長さを a とする。
等円の半径と中心座標を r, (x, r), (r, y)
とおき,以下の連立方程式を解く

include("julia-source.txt");
# julia-source.txt ソース https://blog.goo.ne.jp/r-de-r/e/ad3a427b84bb416c4f5b73089ae813cf

using SymPy

@syms r::positive, x::positive, y::positive, a::positive,
     鈎::positive, 股::positive
eq1 = distance(0, 0, a/2, sqrt(Sym(3))a/2, r, y) - r^2
eq2 = distance(a, 0, a/2, sqrt(Sym(3))a/2, x, r) - r^2
eq3 = distance(0, 鈎, 股, 0, r, y) - r^2
eq4 = distance(0, 鈎, 股, 0, x, r) - r^2
eq5 = (sqrt(Sym(3))a/2)/(股 - a/2) - 鈎/股;
# res = solve([eq1, eq2, eq3, eq4, eq5], (r, x, y, a, 鈎))

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)
   (r, x, y, a, 鈎) = u
   return [
       -r^2 + (3*r/4 - sqrt(3)*y/4)^2 + (-sqrt(3)*r/4 + y/4)^2,  # eq1
       -r^2 + (r - sqrt(3)*(a + sqrt(3)*r - x)/4)^2 + (-3*a/4 + sqrt(3)*r/4 + 3*x/4)^2,  # eq2
       -r^2 + (r - 股*(r*股 - y*鈎 + 鈎^2)/(股^2 + 鈎^2))^2 + (y - 鈎*(-r*股 + y*鈎 + 股^2)/(股^2 + 鈎^2))^2,  # eq3
       -r^2 + (r - 鈎*(r*鈎 - x*股 + 股^2)/(股^2 + 鈎^2))^2 + (x - 股*(-r*鈎 + x*股 + 鈎^2)/(股^2 + 鈎^2))^2,  # eq4
       sqrt(3)*a/(2*(-a/2 + 股)) - 鈎/股,  # eq5
   ]
end;

股 = 487
iniv = BigFloat[56, 295, 209, 263, 312]
res = nls(H, ini=iniv

   (BigFloat[56.11416043991601035847741706383402473599898003302003798949966598270036579889394, 295.3980059252043265908683636932107368735334613723332636723610589520722219482431, 209.4208977858381008824304265789438848352208122172291274041824122497419576667868, 263.0004802898689700383037446882855378574200007464121970616614846371699418629093, 312.0159697201720972932632403222578260473761673054778157588165017227055663499631], true)

股の長さが 487 寸のとき,正三角形の一辺の長さはほぼ 263 寸である。

その他のパラメータは以下の通り。
r = 56.1142;  x = 295.398;  y = 209.421;  a = 263;  鈎 = 312.016

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   股 = 487
   (r, x, y, a, 鈎) = res[1]
   @printf("正三角形の一辺の長さ = %.10g;  r = %g;  x = %g;  y = %g;  a = %g;  鈎 = %g\n", a, r, x, y, a, 鈎)
   plot([0, 股, 0, 0], [0, 0, 鈎, 0], color=:gray80, lw=0.5)
   plot!([0, a, a/2, 0], [0, 0, √3a/2, 0], color=:gray80, lw=0.5)
   circle(r, y, r, :blue)
   circle(x, r, r, :blue)
   if more
       delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3  # size[2] * fontsize * 2
       vline!([0], color=:gray80, lw=0.5)
       hline!([0], color=:gray80, lw=0.5)
       point(a/2, √3a/2, "(a/2,√3a/2)")
       point(x, r, "(x,r)", :blue, :center, delta=-delta/2)
       point(r, y, "(r,y)", :blue, :center, delta=-delta/2)
       point(股, 0, "股", :black, :left, :bottom, delta=delta/2)
       point(a, 0, "a ", :black, :right, :bottom, delta=delta/2)
       point(0, 鈎, "鈎", :black, :left, :bottom, delta=delta/2)
   end
end;

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

算額(その631)

2024年01月11日 | Julia

算額(その631)

和算図形問題あれこれ
https://gunmawasan.web.fc2.com/kongetu-no-mondai.html

長方形の中に,菱形,大円 2 個,小円 4 個が入っている。小円は長方形に内接し,大円,菱形に外接している。大円は互いに外接し,長方形に内接し,小円に外接している。算額の図では大円は互いに接していないように見えるが,実際は接している。
長方形の短辺の長さが 2 寸 5 分のとき小円の直径はいかほどか。

長方形の長辺,短辺の長さを 2a, 2b とする。
大円の半径と中心座標を r1, (0, r1); r = b/2
小円の半径と中心座標を r2, ((a - r2, b - r2)
とおき,以下の連立方程式を解く。

include("julia-source.txt");
# julia-source.txt ソース https://blog.goo.ne.jp/r-de-r/e/ad3a427b84bb416c4f5b73089ae813cf

using SymPy

@syms a::positive, b::positive, r1::positive, r2::positive
r1 = b//2
eq1 = (a - r2)^2 + (b - r2 - r1)^2 - (r1 + r2)^2
eq2 = distance(a, 0, 0, b, a - r2, b - r2) - r2^2
res = solve([eq1, eq2], (a, r2))

   1-element Vector{Tuple{Sym, Sym}}:
    (b*(5 + 3*sqrt(17))/16, b*(9 - sqrt(17))/16)

長方形の長辺の長さは b(5 + 3√17)/8,小円の直径は b(9 - √17)/8 である。
長方形の短辺の長さが 2 寸 5 分のとき,長辺の長さは 2 寸 7 分 1 厘 4 毛ほど,小円の直径は 7 分 6 厘 2 毛ほどである。

b = 2.5/2
b .* ((5 + 3√17)/8, (9 - √17)/8)

   (2.713955762008278, 0.7620147459972405)

その他のパラメータは以下の通り。

b = 1.25;  r1 = 0.625;  r2 = 0.381007

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   b = 2.5/2
   r1 = b/2
   (a, r2) = (25/64 + 15*sqrt(17)/64, 45/64 - 5*sqrt(17)/64)
   @printf("小円の直径 = %g;  b = %g;  r1 = %g;  r2 = %g\n", 2r2, b, r1, r2)
   plot([a, a, -a, -a, a], [-b, b, b, -b, -b], color=:gray80, lw=0.5)
   plot!([a, 0, -a, 0, a], [0, b, 0, -b, 0], color=:gray80, lw=0.5)
   circle4(a - r2, b - r2, r2)
   circle(0, r1, r1, :blue)
   circle(0, -r1, r1, :blue)
   if more
       delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3  # size[2] * fontsize * 2
       vline!([0], color=:gray80, lw=0.5)
       hline!([0], color=:gray80, lw=0.5)
       point(0, r1, " 大円:r1\n (0,r1)", :blue, :left, :vcenter)
       point(a - r2, b - r2, " 小円:r2\n (a-r2,b-r2)", :red, :center, delta=-delta/2)
       point(0, b, " b", :black, :left, :bottom, delta=delta/2)
       point(a, 0, " a", :black, :left, :vcenter)
   end
end;

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

算額(その630)

2024年01月11日 | Julia

算額(その630)

和算図形問題あれこれ
令和4年8月の問題-No.1

https://gunmawasan.web.fc2.com/kongetu-no-mondai.html

正三角形内に斜線を 3 本引き,分割された領域に直径が 1174 寸の等円を 3 個入れる。正三角形の一辺の長さを求めよ。

正三角形の一辺の長さを 2a とする。
等円の半径と中心座標を r, (x, r), (0, 3r)
とおき,以下の連立方程式を解く。

include("julia-source.txt");
# julia-source.txt ソース https://blog.goo.ne.jp/r-de-r/e/ad3a427b84bb416c4f5b73089ae813cf

using SymPy

@syms a::positive, b::positive, x::positive, r::positive

r = 1174//2
eq1 = r/(a - x) - 1/sqrt(Sym(3))
三角形の相似から x を求める
r2 = sqrt(Sym(3))a - 2r  # 三角形の頂点から真ん中の等円の下端までの距離
r3 = sqrt(Sym(3))a - 3r  # 三角形の頂点から真ん中の等円の中心までの距離
eq2 = 2r*r2/sqrt(r3^2 - r^2) - x
eq3 = r/r3 - b/sqrt(3a^2 + b^2);
res = solve([eq1, eq2, eq3], (a, b, x))

   1-element Vector{Tuple{Sym, Sym, Sym}}:
    (587*sqrt(11)/2 + 1761*sqrt(3)/2, 587*sqrt(3), 587*sqrt(3)/2 + 587*sqrt(11)/2)

res[1][1] |> factor |> println

   587*(sqrt(11) + 3*sqrt(3))/2

正三角形の一辺の長さは 2a = (√11 + 3√3)*等円直径/2 = 4997.000224067413 である。

(√11 + 3√3)*1174/2 |> println

   4997.000224067413

正三角形の一辺の長さ = 4997.000224;  等円の直径 = 1174
a = 2498.5;  b = 1016.71;  x = 1481.79

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r = 1174//2
   (a, b, x) = (587*sqrt(11)/2 + 1761*sqrt(3)/2, 587*sqrt(3), 587*sqrt(3)/2 + 587*sqrt(11)/2)
   @printf("正三角形の一辺の長さ = %.10g;  等円の直径 = %g;  a = %g;  b = %g;  x = %g\n", 2a, 2r, a, b, x)
   plot()
   vline!([0], color=:gray80, lw=0.5)
   hline!([0], color=:gray80, lw=0.5)
   plot!([a, 0, -a, a], [0, √3a, 0, 0], color=:green, lw=0.5)
   circle(x, r, r)
   circle(0, 3r, r)
   c = (√3a - 2r)/√3
   segment(0, √3a, b, 0, :blue)
   segment(0, √3a, -b, 0, :blue)
   segment(-c, 2r, c, 2r, :blue)
   if more
       delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3  # size[2] * fontsize * 2
       point(0, 3r, " 3r", :red, :left, :vcenter)
       point(x, r, "(x,r)", :red, :center, delta=-delta/2)
       point(0, √3a, " √3a", :black, :left, :vcenter)
       point(a, 0, "a", :blue, :center, delta=-delta)
       point(b, 0, "b", :blue, :center, delta=-delta)
       plot!(ylims=(-300, √3a+100))
   end
end;

 

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

算額(その628)

2024年01月11日 | Julia

算額(その628)

和算図形問題あれこれ
令和3年12月の問題2

https://gunmawasan.web.fc2.com/kongetu-no-mondai.html

二等辺三角形の内外に甲円 2 個を置き,その間に乙円,丙円,丁円を入れる。甲円の直径が 6寸のとき,乙円,丙円,丁円の直径と三角形の底辺の長さを求めよ。

三角形の底辺の長さを 2a とする。
甲円の半径と中心座標を r1, (0, r1), (0, 3r1)
乙円の半径と中心座標を r2, (x2, y2)
丙円の半径と中心座標を r3, (0, 2r1 + r3)
丁円の半径と中心座標を r4, (x4, y4)
とおき,以下の連立方程式を解く。

SymPy の能力上,まとめて解くことができないようなので,最初に独立な 3 変数の解を求め,続いてそれらが既知として残りのパラメータを求める。

include("julia-source.txt");
# julia-source.txt ソース https://blog.goo.ne.jp/r-de-r/e/ad3a427b84bb416c4f5b73089ae813cf

using SymPy

@syms r1::positive, r2::positive, x2::positive, y2::positive, a::positive, r3::positive, r4::positive, x4::positive, y4::positive

sinθ = r1/3r1
eq1 = (4r1 - (2r1 + r3))sinθ - r3
eq2 = a/sqrt((4r1)^2 + a^2) - sinθ
eq3 = r1*sinθ - (r1 - 2r2);

res1 = solve([eq1, eq2, eq3], (a, r2, r3))

   Dict{Any, Any} with 3 entries:
     r3 => r1/2
     a  => sqrt(2)*r1
     r2 => r1/3

乙円,丙円の直径,底辺の長さは甲円の直径の 1/3,1/2, √2 倍である。
甲円の直径が 6 寸のとき,乙円,丙円の直径は 2 寸,3 寸である。底辺の長さは 6√2 ≒ 8.48528 寸である。

@syms r1::positive, r2::positive, x2::positive, y2::positive, a::positive, r3::positive, r4::positive, x4::positive, y4::positive

(a, r2, r3) = r1 .* (sqrt(Sym(2)), 1//3, 1//2)
eq4 = x4^2 + (3r1 - y4)^2 - (r1 + r4)^2
eq5 = x4^2 + (y4 - r1)^2 - (r1 + r4)^2
eq6 = distance(0, 4r1, a, 0, x4, y4) - r4^2
eq7 = x2^2 + (y2 - 3r1)^2 - (r1 - r2)^2
eq8 = (y2 - 3r1)/x2 *(-4r1)/a + 1
res2 = solve([eq4, eq5, eq6, eq7, eq8], (x2, y2, r4, x4, y4))

   2-element Vector{NTuple{5, Sym}}:
    (4*sqrt(2)*r1/9, 29*r1/9, 2*r1, 2*sqrt(2)*r1, 2*r1)
    (4*sqrt(2)*r1/9, 29*r1/9, 2*r1*(7 - 4*sqrt(3)), -2*sqrt(2)*r1*(35 - 21*sqrt(3))/7, 2*r1)

2 番目のものが適解である。

丁円の直径は甲円の直径の 2(7-4√3) 倍である。
甲円の直径が 6 寸のとき,丁円の直径は 6*2(7-4√3) ≒ 0.861561 である。

乙円の直径 = 2;  丙円の直径 = 3; 丁円の直径(12(7-4√3)) = 0.861561;  底辺(6√2) = 8.48528

その他のパラメータは以下の通り。
a = 4.24264;  r1 = 3;  r2 = 1;  r3 = 1.5;  r4 = 0.430781;  x2 = 1.88562;  y2 = 9.66667; x4 = 1.66441;  y4 = 6

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r1 = 6//2
   (a, r2, r3) = r1 .* (sqrt(Sym(2)), 1//3, 1//2)
   (x2, y2, r4, x4, y4) = r1 .* (4*sqrt(2)/9, 29/9, 2(7 - 4*sqrt(3)), -2*sqrt(2)*(35 - 21*sqrt(3))/7, 2)
   @printf("乙円の直径 = %g;  丙円の直径 = %g; 丁円の直径 = %g;  底辺 = %g\n", 2r2, 2r3, 2r4, 2a)
   @printf("a = %g;  r1 = %g;  r2 = %g;  r3 = %g;  r4 = %g;  x2 = %g;  y2 = %g; x4 = %g;  y4 = %g\n", a, r1, r2, r3, r4, x2, y2, x4, y4)
   plot([a, 0, -a, 0], [0, 4r1, 0, 0], color=:orange, lw=0.5)
   circle(0, r1, r1)
   circle(0, 3r1, r1)
   circle(0, 2r1 + r3, r3, :blue)
   circle(x2, y2, r2, :green)
   circle(-x2, y2, r2, :green)
   circle(x4, y4, r4, :black)
   circle(-x4, y4, r4, :black)
   if more
       delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3  # size[2] * fontsize * 2
       vline!([0], color=:black, lw=0.5)
       hline!([0], color=:black, lw=0.5)
       point(0, r1, " 甲円:r1,(0,r1)", :red, :left, :vcenter)
       point(0, 3r1, " 3r1", :red, :left, :vcenter)
       point(x2, y2, "乙円:r2\n(x2,y2)", :green, :center, :top, delta=-delta/2)
       point(0, 2r1 + r3, " 丙円:r3\n (0,2r1+r3)", :blue, :left, :vcenter)
       point(x4, y4, " 丁円:r4,(x4,y4)", :black, :left, :vcenter)
       point(a, 0, "a", :black, :left, :bottom, delta=delta)
       point(0, 4r1, " 4r1", :black, :left, :bottom)
   end
end;

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

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

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