裏 RjpWiki

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

算額(その157)

2023年03月12日 | Julia

算額(その157

岐阜県大垣市西外側町 大垣八幡神社 天保年間
http://ryugen3.sakura.ne.jp/toukou3/wasankibousya.PDF

第6問: 直角三角形内に黃,赤,黒の半円を入れる。黃,赤の半円の直径を知って黒の半円の直径を求めよ。

黃,赤,黒の半円の半径を r1, r2, r3,斜辺が x 軸,y 軸と交差する点の座標を x,y と置く。関係式を解き,r3 を求める。2倍すれば直径である。

using SymPy

@syms r1::positive, r2::positive, r3::positive, x::negative, y::positive;

eq1 = 2r2 / (2r1 - r2) - (2r2 - r3) / 2r3
eq2 = (2r2 - r3)/2r3 +y/x
eq3 = (2r2 - r3)/2r3*(x + r2) + r1 + 2r2
res = solve([eq1, eq2, eq3], (r3, x, y))

   1-element Vector{Tuple{Sym, Sym, Sym}}:
    (2*r2*(2*r1 - r2)/(2*r1 + 3*r2), -r1^2/r2 - 3*r1/2, r1*(2*r1 + 3*r2)/(2*r1 - r2))

res[1][1] |> println  # r3: 黒の半径

   2*r2*(2*r1 - r2)/(2*r1 + 3*r2)

黒の直径は 4*赤*(2*黃 - 赤)/(2*黃 + 3*赤)

(2*res[1][1])(r1 => 5/2, r2 => 3/2).evalf()

   2.21052631578947

術文 赤径 / 2(赤径 / (2黃径 - 赤径) + 1/4) なる式を掲げているが,たいしてきれいでもない。

res2 = 2r2 / 2(2r2 / (4r1 - 2r2)+1/4)
res2(r1 => 5/2, r2 => 3/2).evalf()

   2.21052631578947

using Plots
using Printf

function circle(ox, oy, r, color=:red; beginangle=0, endangle=360, fill=false)
   θ = beginangle:0.1:endangle
   x = r.*cosd.(θ)
   y = r.*sind.(θ)
   if fill
       plot!(ox .+ x, oy .+ y, linecolor=color, linewidth=0.5, seriestype=:shape, fillcolor=color)
   else
       plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
   end
end;

function point(x, y, string="", color=:green, position=:left, vertical=:top; mark=true)
   mark && scatter!([x], [y], color=color, markerstrokewidth=0)
   annotate!(x, y, text(string, 10, position, color, vertical))
end;

function draw(r1, r2, more)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (r1, r2) = (r1, r2) ./ 2
   (r3, x, y) = (2*r2*(2*r1 - r2)/(2*r1 + 3*r2), -r1^2/r2 - 3*r1/2, r1*(2*r1 + 3*r2)/(2*r1 - r2))
   println("黃の直径 = $(2r1),赤の直径 = $(2r2),黒の直径 = $(2r3)")
   plot()
   circle(-r1, r1, r1, :yellow, beginangle=180, endangle=360, fill=true)
   circle(-r2, r1 + r2, r2, :red, beginangle=270, endangle=450, fill=true)
   circle(-r2 - r3, r1 + r3, r3, :black, beginangle=180, endangle=360, fill=true)
   plot!([0, 0, x, 0], [0, y, 0, 0], color=1, lw=0.5)
   if more == true
       point(0, r1, " r1")
       point(0, r1 + r3, " r1+r3")
       point(0, r1 + r2, " r1+r2")
       point(0, r1 + 2r2, " r1+2r2")
       point(-r1, 0, "-r1", :green, :center, :bottom)
       point(-r2, 0, "-r2", :green, :center, :bottom)
       point(-r2 - 2r3, 0, "-r2-2r3", :green, :center, :bottom)
       point(-2r1, 0, "-2r1", :green, :center, :bottom)
       point(0, y, " y")
       point(x, 0, "x ", :green, :right, :bottom)
       hline!([0, r1, r1 + r3, r1 + r2, r1 + 2r2], color=:gray, linestyle=:dot, lw=0.5)
       vline!([0, -r2, -r1, -r2 - 2r3, -2r1], color=:gray, linestyle=:dot, lw=0.5)
   else
       plot!(showaxis=false)
   end
end;

draw(11, 5, false)

   黃の直径 = 11.0,赤の直径 = 5.0,黒の直径 = 4.594594594594595

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

算額(その156)

2023年03月12日 | Julia

算額(その156)

岐阜県大垣市西外側町 大垣八幡神社 天保年間
http://ryugen3.sakura.ne.jp/toukou3/wasankibousya.PDF

第8問: 図のように正方形を5個描く。中央の正方形には赤円を5個入れる。残りの正方形は中央の正方形と交差し赤円を共有し残りの部分に青円を描く。青円の直径を知って赤円の直径を求めよ。

赤円,青円の半径を r1, r2 とする。AB, CD を r1, r2 で表し,関係式を解く。

赤円の半径と黒円の半径の比は res[r1] / res[r2]

using SymPy

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

AB = (1 + 2√Sym(2))r1
CD = 2√Sym(2)r1 + (1 + √Sym(2))r2
solve(2AB - CD, r1)[1] |> println

   r2/2

赤円の半径 = 青円の半径/2
すなわち,赤円の直径は青円の直径の半分である。

using Plots
using Printf

function circle(ox, oy, r, color=:red; beginangle=0, endangle=360, fill=false)
   θ = beginangle:0.1:endangle
   x = r.*cosd.(θ)
   y = r.*sind.(θ)
   if fill
       plot!(ox .+ x, oy .+ y, linecolor=color, linewidth=0.5, seriestype=:shape, fillcolor=color)
   else
       plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
   end
end;

function point(x, y, string="", color=:green, position=:left, vertical=:top; mark=true)
   mark && scatter!([x], [y], color=color, markerstrokewidth=0)
   annotate!(x, y, text(string, 10, position, color, vertical))
end;

function diamond(ox, oy, r1, color=:yellow)
   l = (1 + 2√2)r1
   plot!(ox .+ [l, 0, -l, 0, l], oy .+ [0, l, 0, -l, 0], linecolor=:black, linewidth=0.5, seriestype=:shape, fillcolor=color)
   if color == :plum1
       circle(0, 0, r1, :tomato1, fill=true)
       center = (1 + √2)r1
       circle(center, 0, r1, :tomato1, fill=true)
       plot!([center, r1, center], [√2r1, 0, -√2r1], color=:black, lw=0.5)
       circle(-center, 0, r1, :tomato1, fill=true)
       plot!([√2r1, 0, -√2r1], [center, r1, center], color=:black, lw=0.5)
       circle(0, center, r1, :tomato1, fill=true)
       plot!([-center, -r1, -center], [√2r1, 0, -√2r1], color=:black, lw=0.5)
       circle(0, -center, r1, :tomato1, fill=true)
       plot!([√2r1, 0, -√2r1], [-center, -r1, -center], color=:black, lw=0.5)
   else
       circle(ox + sign(ox)*r1, oy + sign(oy)*r1, 2r1, :steelblue1, fill=true)
   end
end

function draw(more)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r1 = 1
   plot()
   diamond((2 + 2√2)r1, 0, r1)
   diamond(-(2 + 2√2)r1, 0, r1)
   diamond(0, (2 + 2√2)r1, r1)
   diamond(0, -(2 + 2√2)r1, r1)
   diamond(0, 0, r1, :plum1)
   if more == true
       point(0, 0, " A", :white)
       point((1 + 2√2)r1, 0, " B", :white)
       point(r1, 0, "  C", :white)
       point((3 + 4√2)r1, 0, " D", :black)
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
   else
       plot!(showaxis=false)
   end
end;

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

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

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