裏 RjpWiki

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

算額(その1047)

2024年06月11日 | Julia

算額(その1047)

八十二 藤沢町保呂羽保呂羽山 保呂羽神社 明治7年(1874)
山村善夫:現存 岩手の算額,昭和52年1月30日,熊谷印刷,盛岡市.

http://www.wasan.jp/yamamura/yamamura.html

直線の上に小円 2 個が互いに接して載っている。その上に,小円を 3 個含む,交差する大円 2 個が載っている。
黒積(図で灰色に塗った面積)を求めよ。



手計算すればよいのだが,大円とy 軸の交点の y 座標を求める。

include("julia-source.txt");

using SymPy
@syms r1::positive, r2::negative, x::positive, y::positive
r1 = 2r2
eq1 = (x - r2)^2 + (y - 4r2)^2 - 4r2^2
solve(eq1, y)[2](x => 0) |> println

   sqrt(3)*(-r2) + 4*r2

求める面積(黒積)は「台形OABC の面積から大円の面積の 1/12(OAD) と小円の面積の 1/4(CBD) を差し引いた面積の 2 倍」である。

# 台形OABC の面積
S1 = ((1 + (2 - √Sym(3))) + 3)/2*r2^2
S1 |> println
# 大円の面積の 1/12
S2 = PI*(2r2)^2/12
S2 |> println
# 小円の面積の 1/4 
S3 = PI*r2^2/4
S3 |> println

   r2^2*(3 - sqrt(3)/2)
   pi*r2^2/3
   pi*r2^2/4

小円の直径が 1 寸のときの黒積は -7*π/24 - sqrt(3)/4 + 3/2 = 0.150689440810758 である。

black = 2(S1 - S2 - S3)(r2 => 1//2)
black |> println
black.evalf() |> println

   -7*pi/24 - sqrt(3)/4 + 3/2
   0.150689440810758

function paintitblack(r2)
   θ = 240:0.1:270
   x = 2r2.*cosd.(θ) .+ r2
   y = 2r2.*sind.(θ) .+ 4r2
   θ2 = 90:0.1:180
   append!(x, r2.*cosd.(θ2) .+ r2)
   append!(y, r2.*sind.(θ2) .+ r2)
   append!(x, -reverse(x))
   append!(y, reverse(y))
   append!(x, [0, 0])
   append!(y, [r2, r2*(3 - √3)])
   plot!(x, y, seriestype=:shape, fillcolor=:gray80)
end;

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r2 = 1/2
   r1 = 2r2
   plot(r2.*[1, 0, 0, 1, 1], r2.*[4, 4 - √3, 1, 1, 4], color=:black, lw=1)
   circle2(r2, 4r2, r1)
   circle(0, 4r2, r2, :blue)
   circle2(r2, r2, r2, :blue)
   circle2(2r2, 4r2, r2, :blue)
   paintitblack(r2)
   segment(-3r2, 0, 3r2, 0, :black, lw=1)
   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(r2, 4r2, "O ", :black, :right, :vcenter)
       point(0, r2*(4 - √3), "A ", :black, :center, :bottom, delta=delta)
       point(0, r2, "B ", :black, :right, :vcenter)
       point(r2, r2, " C", :black, :left, :vcenter)
       point(r2, 2r2, " D", :black, :left, :bottom, delta=delta)
       point(0, 4*r2 - sqrt(3)*r2)
       point(0, 4r2, "小円:r2,(0,4r2)", :blue, :center, :bottom, delta=delta)
       point(r2, r2, "小円:r2,(r2,r2)", :blue, :center, delta=-delta)
       point(r2, 4r2, " 大円:2r2,(r2,4r2)", :red, :left, :vcenter)
   end
end;

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

算額(その1046)

2024年06月11日 | Julia

算額(その1046)

八十二 藤沢町保呂羽保呂羽山 保呂羽神社 明治7年(1874)
山村善夫:現存 岩手の算額,昭和52年1月30日,熊谷印刷,盛岡市.

http://www.wasan.jp/yamamura/yamamura.html

正三角形の中に全円,大円,小円と斜線を容れる。小円の直径が 1 寸のとき,大円の直径はいかほどか。

正三角形の一辺の長さを 2a
全円の半径と中心座標を r0, (0, r0); r0 = √3a/3
大円の半径と中心座標を r1, (x1, r1); x1 < 0
小円の半径と中心座標を r2, (x2, r2)
斜線と斜辺の交点座標を (b, √3(b + a)); b < 0
とおき,以下の連立方程式を解く。

一度に解けないので,逐次解いてゆく。

include("julia-source.txt");

using SymPy
@syms a::positive, b::negative, r0::positive,
     r1::positive, x1::negative, r2::positive, x2::positive,
     y2::positive
r0 = √Sym(3)a/3
eq1 = dist2(a, 0, 0, √Sym(3)a, x2, y2, r2)
eq2 = dist2(-a, 0, 0, √Sym(3)a, x1, r1, r1)
eq3 = dist2(a, 0, b, √Sym(3)*(b + a), x2, y2, r2)
eq4 = dist2(a, 0, b, √Sym(3)*(b + a), x1, r1, r1)
eq5 = x2^2 + (r0 - y2)^2 - (r0 + r2)^2
eq6 = x1^2 + (r0 - r1)^2 - (r0 + r1)^2;

eq2, eq6 から a, x1 を求める。

res = solve([eq2, eq6], (a, x1))[2]

   (3*sqrt(3)*r1, -2*sqrt(3)*r1)

eq1, eq3, eq5, eq6 に a, x1 を代入する。

eq1 = 4eq1(a => res[1]);
eq3 = numerator(eq3(a => res[1]));
eq4 = numerator(eq4(a => res[1], x1 => res[2]));
eq5 = eq5(a => res[1]);

eq1 |> println
eq3 |> println
eq4 |> println
eq5 |> println

   81*r1^2 - 18*sqrt(3)*r1*x2 - 18*r1*y2 - 4*r2^2 + 3*x2^2 + 2*sqrt(3)*x2*y2 + y2^2
   81*b^2*r1^2 - 18*sqrt(3)*b^2*r1*x2 + 18*b^2*r1*y2 - 4*b^2*r2^2 + 3*b^2*x2^2 - 2*sqrt(3)*b^2*x2*y2 + b^2*y2^2 + 486*sqrt(3)*b*r1^3 - 324*b*r1^2*x2 - 12*sqrt(3)*b*r1*r2^2 + 18*sqrt(3)*b*r1*x2^2 - 6*sqrt(3)*b*r1*y2^2 + 2187*r1^4 - 486*sqrt(3)*r1^3*x2 - 486*r1^3*y2 - 108*r1^2*r2^2 + 81*r1^2*x2^2 + 54*sqrt(3)*r1^2*x2*y2 + 27*r1^2*y2^2
   252*b^2*r1^2 + 1332*sqrt(3)*b*r1^3 + 5184*r1^4
   x2^2 - (3*r1 + r2)^2 + (3*r1 - y2)^2

eq4 を解いて b を求める。

ans_b = solve(eq4, b)[2]
ans_b |> println

   -16*sqrt(3)*r1/7

eq3, eq5 の b に ans_b を代入する。

eq3 = 49eq3(b => ans_b)/r1^2 |> simplify
eq5 = eq5(b => ans_b) |> expand |> simplify;

eq1 |> println
eq3 |> println
eq5 |> println

   81*r1^2 - 18*sqrt(3)*r1*x2 - 18*r1*y2 - 4*r2^2 + 3*x2^2 + 2*sqrt(3)*x2*y2 + y2^2
   6075*r1^2 - 1350*sqrt(3)*r1*x2 - 9990*r1*y2 - 4332*r2^2 + 225*x2^2 + 1110*sqrt(3)*x2*y2 + 4107*y2^2
   -6*r1*r2 - 6*r1*y2 - r2^2 + x2^2 + y2^2

eq1, eq3, eq5 を解いて r1, x2, y2 を求める。

res2 = solve([eq1, eq3, eq5], (r1, x2, y2))[3];  # 3 of 3

res2[1] |> println
res2[2] |> println
res2[3] |> println

   2*r2*(sqrt(5) + 3)/9
   5*sqrt(3)*r2/6 + 2*sqrt(15)*r2/3
   3*r2/2

res2[1](r2 => 1/2).evalf() |> println
res2[2](r2 => 1/2).evalf() |> println
res2[3](r2 => 1/2).evalf() |> println

   0.581785330833310
   2.01268228522284
   0.750000000000000

大円の半径 r1 は,小円の半径 r2 の 2(√5 + 3)/9 倍である。
小円の直径が 1 寸のとき大円の直径は 2(√5 + 3)/9 = 1.16357066166662 寸である。
「術」の「小円径×(√20 + 6)/9」 と一致した。

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r2 = 1/2
   r1 = r2*2(√5 + 3)/9
   x2 = r2*(5√3/6 + 2√15/3)
   y2 = r2*3/2
   b = r1*(-16√3/7)
   a = r1*3√3
   x1 = -2√3*r1
   r0 = a/√3
   plot([a, 0, -a, a], [0, √3a, 0, 0], color=:blue, lw=0.5)
   circle(0, √3a/3, √3a/3)
   circle(x1, r1, r1, :green)
   circle(x2, y2, r2, :magenta)
   segment(a, 0, b, √3(b + a))
   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, r0, "全円:r0\n(0,r0)", :red, :center, :bottom, delta=delta/2)
       point(x1, r1, "大円:r1\n(x1,r1)", :green, :center, :bottom, delta=delta/2)
       point(x2, y2, "小円:r2\n(x2,y2)", :magenta, :center, :bottom, delta=delta/2)
       point(a, 0, " a", :blue, :left, :bottom, delta=delta/2)
       point(0, √3a, " √3a", :blue, :left, :vcenter)
   end
end;

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

算額(その1045)

2024年06月11日 | Julia

算額(その1045)

八十七 室根村矢越 矢越弥栄神社 昭和4年(1929)
山村善夫:現存 岩手の算額,昭和52年1月30日,熊谷印刷,盛岡市.

http://www.wasan.jp/yamamura/yamamura.html

外円の中に甲円,乙円,丙円,丁円が入っている。甲円と丙円の直径がそれぞれ 2 寸,6 寸のとき,乙円の直径はいかほどか。

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

include("julia-source.txt");

using SymPy
@syms R::positive, r1::positive, y1::positive,
     r2::positive, x2::positive, y2::positive,
     r3::positive, y3::negative,
     r4::positive, y4::positive
eq1 = r1^2 + y1^2 - (R - r1)^2 |> expand
eq2 = x2^2 + y2^2 - (R - r2)^2 |> expand
eq3 = r3^2 + y3^2 - (R - r3)^2 |> expand
eq4 = (x2 - r1)^2 + (y1 - y2)^2 - (r1 + r2)^2 |> expand
eq5 = r1^2 + (y1 - y4)^2 - (r1 + r4)^2 |> expand
eq6 = (x2 - r3)^2 + (y2 - y3)^2 - (r2 + r3)^2 |> expand
eq7 = x2^2 + (y4 - y2)^2 - (r2 + r4)^2 |> expand
eq8 = r3^2 + (y4 - y3)^2 - (r3 + r4)^2 |> expand;

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 [
       -R^2 + 2*R*r1 + y1^2,  # eq1
       -R^2 + 2*R*r2 - r2^2 + x2^2 + y2^2,  # eq2
       -R^2 + 2*R*r3 + y3^2,  # eq3
       -2*r1*r2 - 2*r1*x2 - r2^2 + x2^2 + y1^2 - 2*y1*y2 + y2^2,  # eq4
       -2*r1*r4 - r4^2 + y1^2 - 2*y1*y4 + y4^2,  # eq5
       -r2^2 - 2*r2*r3 - 2*r3*x2 + x2^2 + y2^2 - 2*y2*y3 + y3^2,  # eq6
       -r2^2 - 2*r2*r4 - r4^2 + x2^2 + y2^2 - 2*y2*y4 + y4^2,  # eq7
       -2*r3*r4 - r4^2 + y3^2 - 2*y3*y4 + y4^2,  # eq8
   ]
end;
(r1, r3) = (2, 6)./2
iniv = BigFloat[6, 5, 1, 3, 4, -1, 2, 3]
res = nls(H, ini=iniv)

   ([6.147114317029974, 5.049038105676658, 1.5, 3.0, 3.549038105676658, -0.950961894323342, 1.647114317029974, 2.598076211353316], true)

甲円,丙円の直径が 2, 6 のとき,乙円の直径は 3 である。

その他のパラメータは以下のとおりである。

r1 = 1;  r3 = 3;  R = 6.14711;  y1 = 5.04904;  r2 = 1.5;  x2 = 3;  y2 = 3.54904;  y3 = -0.950962;  r4 = 1.64711;  y4 = 2.59808

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (r1, r3) = (2, 6)./2
   (R, y1, r2, x2, y2, y3, r4, y4) = res[1]
   @printf("甲円,丙円の直径が %g, %g のとき,乙円の直径は %g である。\n", 2r1, 2r3, 2r2)
   @printf("r1 = %g;  r3 = %g;  R = %g;  y1 = %g;  r2 = %g;  x2 = %g;  y2 = %g;  y3 = %g;  r4 = %g;  y4 = %g\n", r1, r3, R, y1, r2, x2, y2, y3, r4, y4)
   plot()
   circle(0, 0, R)
   circle2(r1, y1, r1, :blue)
   circle2(x2, y2, r2, :green)
   circle2(r3, y3, r3, :orange)
   circle(0, y4, r4, :magenta)
   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", :red, :left, :bottom, delta=delta/2)
       point(0, R, " R", :red, :left, :bottom, delta=delta/2)
   end
end;

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

算額(その1044)

2024年06月11日 | Julia

算額(その1044)

八十七 室根村矢越 矢越弥栄神社 昭和4年(1929)
山村善夫:現存 岩手の算額,昭和52年1月30日,熊谷印刷,盛岡市.

http://www.wasan.jp/yamamura/yamamura.html

外円の中に甲円 2 個,乙円 4 個,丙円 2 個を容れる。甲円の直径が 4 寸のとき,乙円の直径はいかほどか。

外円の半径と中心座標を R, (0, 0)
甲円の半径と中心座標を r1, (0, R - r1)
乙円の半径と中心座標を r2, (x2, r2)
丙円の半径と中心座標を r3, (0, R - r3)
とおき,以下の連立方程式を立てる。

甲円の半径 r1 は与えられるので,未知数は R, r2, x2, r3 の 4 個であるのに,条件式は 3 本しかない。条件不足かとずいぶん悩んだが,r1 と r2 の関係を求めよということなので「えいままよ」と r3 は未知数ではないと仮定して R, r2, x2 を求めてみる。
あれ不思議,r2 は r1/2 ということで,r3 は関与していない。つまり,r3 がどんな数でも(外円の大きさは r3 によって変化するが),常に r2 = r1/2 ということである。
すなわち,甲円の直径が 4 寸なら,乙円の直径は 2 寸である。

include("julia-source.txt");

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

   (r1 + r3, r1/2, sqrt(r3)*sqrt(r1 + r3))

function draw(r1, r3, more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (R, r2, x2) = (r1 + r3, r1/2, sqrt(r3)*sqrt(r1 + r3))
   @printf("甲円の直径が %g のとき,乙円の直径は %g である。\n", 2r1, 2r2)
   @printf("r1 = %g;  r3 = %g;  R = %g;  r2 = %g;  x2 = %g\n", r1, r3, R, r2, x2)
   string = @sprintf("甲円の直径 = %g 丙円の直径 = %g\n乙円の直径 = %g", 2r1, 2r3, 2r2)
   plot()
   circle(0, 0, R)
   circle22(0, R - r1, r1, :blue)
   circle22(0, R - r3, r3, :green)
   circle4(x2, r2, r2, :orange)
   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", :red, :left, :bottom, delta=delta/2)
       point(0, R, " R", :red, :left, :bottom, delta=delta/2)
       point(0, R - r1, "甲:r1,(0,R-r1)", :blue, :center, delta=-delta/2)
       point(0, R - r3, "丙:r3,(0,R-r3)", :green, :center, delta=-delta/2)
       point(x2, r2, "乙:r2\n(R-r2,0)", :orange, :center, delta=-delta/2)
       point(0, -0.75R, string, :black, :left, :vcenter, deltax=-10delta, mark=false)
   end
end;

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

   甲円の直径が 4 のとき,乙円の直径は 2 である。
   r1 = 2;  r3 = 3;  R = 5;  r2 = 1;  x2 = 3.87298

draw(5/2, 7/2, true)

   甲円の直径が 5 のとき,乙円の直径は 2.5 である。
   r1 = 2.5;  r3 = 3.5;  R = 6;  r2 = 1.25;  x2 = 4.58258

甲円の直径と丙円の直径が同じ場合には以下のようになる。
これは「算額(その582)」https://blog.goo.ne.jp/r-de-r/e/a539541dcbea774663b1214354485621 と同じで,甲円と乙円の大きさが 2:1 になるというのは容易に導ける(条件不足にならないから,連立方程式をすんなりと解くことができるから)。

draw(5/2, 5/2, true)

   甲円の直径が 5 のとき,乙円の直径は 2.5 である。
   r1 = 2.5;  r3 = 2.5;  R = 5;  r2 = 1.25;  x2 = 3.53553

 

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

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

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