裏 RjpWiki

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

算額(その526)

2023年12月01日 | Julia

算額(その526)

和算図形問題あれこれ - 令和4年8月の問題-No.2
https://gunmawasan.web.fc2.com/kongetu-no-mondai.html

正方形内に大半円,中半円,小半円,甲円,乙円,丙円が入っている。正方形の一辺の長さが 10 寸のとき,丙円の直径はいかほどか。

大半円の半径と中心座標を r1, (x1, y1); r1 = a/2; x1 = 1; y1 = r1
中半円の半径と中心座標を r2, (x2, y2); x2 = 0; y2 = a - r2
小半円の半径と中心座標を r3, (x3, y3); x3 = r3; y3 = 0
甲円の半径と中心座標を r4, (x4, y4)
乙円の半径と中心座標を r5, (x5, y5)
丙円の半径と中心座標を r6, (x6, y6)
とおき,以下の連立方程式を解く。

include("julia-source.txt");

using SymPy

@syms a::positive,
   r1::positive, x1::positive, y1::positive,
   r2::positive, x2::positive, y2::positive,
   r3::positive, x3::positive, y3::positive,
   r4::positive, x4::positive, y4::positive,
   r5::positive, x5::positive, y5::positive,
   r6::positive, x6::positive, y6::positive;

r1 = a/2; x1 = a; y1 = r1
x2 = 0; y2 = a - r2
x3 = r3; y3 = 0
eq1  = (x1 - x3)^2 + (y1 - y3)^2 - (r1 + r3)^2
eq2  = (x1 - x4)^2 + (y1 - y4)^2 - (r1 + r4)^2
eq3  = (x1 - x5)^2 + (y1 - y5)^2 - (r1 + r5)^2
eq4  = (x1 - x6)^2 + (y1 - y6)^2 - (r1 + r6)^2

eq5  = (x2 - x3)^2 + (y2 - y3)^2 - (r2 + r3)^2
eq6  = (x2 - x4)^2 + (y2 - y4)^2 - (r2 + r4)^2
eq7  = (x2 - x5)^2 + (y2 - y5)^2 - (r2 + r5)^2
eq8  = (x2 - x6)^2 + (y2 - y6)^2 - (r2 + r6)^2

eq9  = (x3 - x4)^2 + (y3 - y4)^2 - (r3 + r4)^2
eq10 = (x4 - x5)^2 + (y4 - y5)^2 - (r4 + r5)^2
eq11 = (x5 - x6)^2 + (y5 - y6)^2 - (r5 + r6)^2;

res = solve([eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10, eq11], (r2, r3, r4, x4, y4, r5, x5, y5, r6, x6, y6))

   2-element Vector{NTuple{11, Sym}}:
    (3*a/8, a/3, 2*a*(-10 + 7*sqrt(3))/47, a*(23 - 2*sqrt(3))/47, a*(23 - 2*sqrt(3))/47, 2*a*(18 - 7*sqrt(3))/177, a*(81 - 2*sqrt(3))/177, a*(51/59 - 10*sqrt(3)/59), a/11, 5*a/11, 8*a/11)
    (3*a/8, a/3, -20*a/47 + 14*sqrt(3)*a/47, -2*sqrt(3)*a/47 + 23*a/47, -2*sqrt(3)*a/47 + 23*a/47, 2*a*(18 - 7*sqrt(3))/177, a*(81 - 2*sqrt(3))/177, a*(51 - 10*sqrt(3))/59, 2*a*(-10 + 7*sqrt(3))/47, a*(23 - 2*sqrt(3))/47, a*(23/47 - 2*sqrt(3)/47))

2 組の解が得られるが,1 番目のものが適解である。

丙円の半径は a/11 である。
a = 10 のとき,直径は 2*10/11 = 1.8181818181818181 である。

res[1][9] |> println

   a/11

a = 10
2a/11

   1.8181818181818181

その他のパラメータ

   r2 = 3.75;  r3 = 3.33333
   r4 = 0.903981;  x4 = 4.15657;  y4 = 4.15657
   r5 = 0.663915;  x5 = 4.38056;  y5 = 5.70839
   r6 = 0.909091;  x6 = 4.54545;  y6 = 7.27273
   丙円の直径 = 1.81818

function draw(more=false)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   a = 10
   (r2, r3, r4, x4, y4, r5, x5, y5, r6, x6, y6) = (
       3*a/8, a/3,
       2*a*(-10 + 7*sqrt(3))/47, a*(23 - 2*sqrt(3))/47, a*(23 - 2*sqrt(3))/47,
       2*a*(18 - 7*sqrt(3))/177, a*(81 - 2*sqrt(3))/177, a*(51/59 - 10*sqrt(3)/59),
       a/11, 5*a/11, 8*a/11)
   r1 = a/2; x1 = a; y1 = r1
   x2 = 0; y2 = a - r2
   x3 = r3; y3 = 0
   @printf("r2 = %g;  r3 = %g\nr4 = %g;  x4 = %g;  y4 = %g\nr5 = %g;  x5 = %g;  y5 = %g\nr6 = %g;  x6 = %g;  y6 = %g\n", r2, r3, r4, x4, y4, r5, x5, y5, r6, x6, y6)
   @printf("丙円の直径 = %g\n", 2r6)
   plot([0, a, a, 0, 0], [0, 0, a, a, 0], color=:black, lw=0.5)
   circle(x1, y1, r1, beginangle=90, endangle=270)
   circle(x2, y2, r2, :blue, beginangle=-90, endangle=90)
   circle(x3, y3, r3, :magenta, beginangle=0, endangle=180)
   circle(x4, y4, r4, :brown)
   circle(x5, y5, r5, :green)
   circle(x6, y6, r6, :orange)
    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(x1, y1, "r1,(x1,y1) ", :black, :right, :top, delta=-delta/2)
       point(x2, y2, " r2,(x2,y2)", :black, :left, :top, delta=-delta/2)
       point(x3, y3, " r3,(x3,y3)", :black, :left, :bottom, delta=delta/2)
       point(x4, y4, " r4,(x4,y4)", :black, :left, :top, delta=-delta/2)
       point(x5, y5, " r5,(x5,y5)", :black, :left, :top, delta=-delta)
       point(x6, y6, " r6,(x6,y6)", :black, :left, :bottom, delta=delta)
       point(a, a, "(a,a) ", :black, :right, :bottom, delta=delta/2)
    end
end;

 

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

算額(その525)

2023年12月01日 | Julia

算額(その525)

和算図形問題あれこれ - 令和4年7月の問題-No.1
https://gunmawasan.web.fc2.com/kongetu-no-mondai.html

正方形内に甲円,乙円,丙円が入っている。甲円の直径が 1 寸のとき,乙円の直径はいくらか。

正方形の一辺の長さを 2a とする。
甲円の半径と中心座標を r1, (a - r1, a - r1)
乙円の半径と中心座標を r2, (a - r2, r2)
丙円の半径と中心座標を r3, (0, 0)
とおき,以下の連立方程式を解く。

include("julia-source.txt");

using SymPy

@syms r1::positive, r2::positive, r3::positive, a::positive;

eq1 = 2(a - r1)^2 - (r3 + r1)^2
eq2 = (a - r2)^2 + r2^2 - (r3 + r2)^2
eq3 = (r1 - r2)^2 + (a - r1 - r2)^2 - (r1 + r2)^2
res = solve([eq1, eq2, eq3], (r2, r3, a))

   3-element Vector{Tuple{Sym, Sym, Sym}}:
    (r1*(-4*sqrt(2) + 5*sqrt(385 - 272*sqrt(2)) + 4*sqrt(770 - 544*sqrt(2)) + 13)/2, r1*(-392*sqrt(2) - 17*sqrt(385 - 272*sqrt(2)) + 16*sqrt(770 - 544*sqrt(2)) + 545)/(-17 + sqrt(385 - 272*sqrt(2)) + 8*sqrt(2)), r1*(-4*sqrt(2) - sqrt(385 - 272*sqrt(2))/2 + 17/2))
    (r1*(-4*sqrt(2) - 4*sqrt(770 - 544*sqrt(2)) - 5*sqrt(385 - 272*sqrt(2)) + 13)/2, r1*(-545 - 17*sqrt(385 - 272*sqrt(2)) + 16*sqrt(770 - 544*sqrt(2)) + 392*sqrt(2))/(-8*sqrt(2) + sqrt(385 - 272*sqrt(2)) + 17), r1*(-4*sqrt(2) + sqrt(385 - 272*sqrt(2))/2 + 17/2))
    (r1*(-4*sqrt(544*sqrt(2) + 770) + 4*sqrt(2) + 13 + 5*sqrt(272*sqrt(2) + 385))/2, r1*(-392*sqrt(2) - 545 + 17*sqrt(272*sqrt(2) + 385) + 16*sqrt(544*sqrt(2) + 770))/(-sqrt(272*sqrt(2) + 385) + 8*sqrt(2) + 17), r1*(-sqrt(272*sqrt(2) + 385)/2 + 4*sqrt(2) + 17/2))

3 組の解が得られるが,2 番目の解が適解である。

半径が 0.5 のとき,乙円の直径は 0.5*(-4√2 - 4sqrt(770 - 544√2) - 5sqrt(385 - 272√2) + 13) ≒ 0.5925393615845476 である。

r1 = 1/2
r1*(-4*sqrt(2) - 4*sqrt(770 - 544*sqrt(2)) - 5*sqrt(385 - 272*sqrt(2)) + 13)

   0.5925393615845476

   r1 = 0.5;  r2 = 0.29627;  r3 = 1.0076;  a = 1.56604
   乙円の直径 = 0.592539

function draw(more=false)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r1 = 1//2
   (r2, r3, a) = (r1*(-4*sqrt(2) - 4*sqrt(770 - 544*sqrt(2)) - 5*sqrt(385 - 272*sqrt(2)) + 13)/2, r1*(-545 - 17*sqrt(385 - 272*sqrt(2)) + 16*sqrt(770 - 544*sqrt(2)) + 392*sqrt(2))/(-8*sqrt(2) + sqrt(385 - 272*sqrt(2)) + 17), r1*(-4*sqrt(2) + sqrt(385 - 272*sqrt(2))/2 + 17/2))
   @printf("r1 = %g;  r2 = %g;  r3 = %g;  a = %g\n", r1, r2, r3, a)
   @printf("乙円の直径 = %g\n", 2r2)
   plot([a, a, -a, -a, a], [-a, a, a, -a, -a], color=:black, lw=0.5)
   circle(0, 0, r3)
   circle4(a - r1, a - r1, r1, :magenta)
   circle4(a - r2, r2, r2, :blue)
   circle4(r2, a - r2, r2, :blue)
    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(a - r1, a - r1, "甲円:r1,(a-r1,a-r1)", :magenta, :center, :top, delta=-delta/2)
       point(a - r2, r2, "乙円:r2,(a-r2,r2) ", :blue, :right, :vcenter)
       point(r3, 0, "r3 ", :red, :right, :bottom, delta=delta/4)
       point(a, 0, "a ", :black, :right, :bottom, delta=delta/4)
    end
end;

 

 

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

算額(その524)

2023年12月01日 | Julia

算額(その524)

和算図形問題あれこれ - 令和4年10月の問題-No.2
https://gunmawasan.web.fc2.com/kongetu-no-mondai.html

外円の中に甲円と乙円が入っている。甲円と乙円の直径が与えられたとき,外円の直径を求めよ。

外円の半径と中心座標を r0, (0, 0)
甲円の半径と中心座標を r1, (0, r0 - r1)
乙円の半径と中心座標を r2, (x2, r3 - r0 - r2)
外円の下部にある円弧の半径と中心座標を r3, (0, -r0)
として,以下の連立方程式を解く。
乙円の半径を求めるためには eq1, eq2, eq3 を解けばよい。
eq4, eq5 は外円と円弧の交点座標を求めるためのものである。

include("julia-source.txt");

using SymPy
@syms r0::positive, r1::positive, r2::positive, x2::positive,
   r3::positive, xa::positive, ya::negative;

eq1 = x2^2 + (r3 - r0 - r2)^2 - (r0 - r2)^2
eq2 = x2^2 + (r3 - r2)^2 - (r2 + r3)^2
eq3 = (r3 - r0) - (r0 - 2r1)
eq4 = xa^2 + ya^2 - r0^2
eq5 = xa^2 +(ya + r0)^2 - r3^2
res = solve([eq1, eq2, eq3, eq4, eq5], (r0, x2, r3, xa, ya))

   4-element Vector{NTuple{5, Sym}}:
    (r1*(r1 - r2)/(r1 - 2*r2), -2*sqrt(2)*sqrt(r1)*r2*sqrt(1/(r1 - 2*r2)), 2*r1*r2/(r1 - 2*r2), -2*r1^(3/2)*r2*sqrt(1/(r1 - 2*r2))/(r1 - r2), -r1*(r1^2 - 2*r1*r2 - r2^2)/((r1 - 2*r2)*(r1 - r2)))
    (r1*(r1 - r2)/(r1 - 2*r2), -2*sqrt(2)*sqrt(r1)*r2*sqrt(1/(r1 - 2*r2)), 2*r1*r2/(r1 - 2*r2), 2*r1^(3/2)*r2*sqrt(1/(r1 - 2*r2))/(r1 - r2), -r1*(r1^2 - 2*r1*r2 - r2^2)/((r1 - 2*r2)*(r1 - r2)))
    (r1*(r1 - r2)/(r1 - 2*r2), 2*sqrt(2)*sqrt(r1)*r2*sqrt(1/(r1 - 2*r2)), 2*r1*r2/(r1 - 2*r2), -2*r1^(3/2)*r2*sqrt(1/(r1 - 2*r2))/(r1 - r2), -r1*(r1^2 - 2*r1*r2 - r2^2)/((r1 - 2*r2)*(r1 - r2)))
    (r1*(r1 - r2)/(r1 - 2*r2), 2*sqrt(2)*sqrt(r1)*r2*sqrt(1/(r1 - 2*r2)), 2*r1*r2/(r1 - 2*r2), 2*r1^(3/2)*r2*sqrt(1/(r1 - 2*r2))/(r1 - r2), -r1*(r1^2 - 2*r1*r2 - r2^2)/((r1 - 2*r2)*(r1 - r2)))

4 組の解が得られる。符号を無視すればどれでもよいが,図のような位置関係ならば 4 番目の解が適解である。

外円の半径は r1*(r1 - r2)/(r1 - 2r2) である。

甲円,乙円の直径が7, 2 の場合,外円の直径は 35/3 ≒ 11.6667 である。

   r0 = 5.83333;  r1 = 3.5;  r2 = 1;  x2 = 4.32049;  r3 = 4.66667;  xa = 4.27707;  ya = -3.96667
   外円の直径 = 11.6667

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (r1, r2) = (7, 2) .// 2
   (r0, x2, r3, xa, ya) = (r1*(r1 - r2)/(r1 - 2*r2), 2*sqrt(2)*sqrt(r1)*r2*sqrt(1/(r1 - 2*r2)), 2*r1*r2/(r1 - 2*r2), 2*r1^(3/2)*r2*sqrt(1/(r1 - 2*r2))/(r1 - r2), -r1*(r1^2 - 2*r1*r2 - r2^2)/((r1 - 2*r2)*(r1 - r2)))
   @printf("r0 = %g;  r1 = %g;  r2 = %g;  x2 = %g;  r3 = %g;  xa = %g;  ya = %g\n", r0, r1, r2, x2, r3, xa, ya)
   @printf("外円の直径 = %g\n", 2r0)
   plot()
   circle(0, 0, r0)
   circle(0, r0 - r1, r1, :blue)
   circle(x2, r3 - r0 - r2, r2, :green)
   circle(-x2, r3 - r0 - r2, r2, :green)
   x = sqrt(r0^2 - (r3 - r0)^2)
   segment(-x, r3 - r0, x, r3 - r0, :orange)
   θ = atand((ya + r0)/xa)
   circle(0, -r0, r3, :magenta, beginangle=θ, endangle=180 - θ)    
   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(0, r3 - r0, " r3-r0", :black, :left, :bottom, delta=delta)
       point(0, r0 - r1, " 甲円:r1\n (0,r0-r1)", :blue, :left, :vcenter)
       point(x2, r3 - r0 - r2, "乙円:r2(x2,r3-r0-r2) ", :black, :right, :vcenter)
       point(xa, ya, " (xa,ya)", :red, :left, :vcenter)
   end
end;

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

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

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