裏 RjpWiki

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

算額(その15)

2022年11月07日 | Julia

算額(その15)

岩手県東磐井郡川崎村 浪分神社 年代不詳(文久か)
http://www.wasan.jp/iwate/namiwake5.html

岩手県陸前高田市気仙町 今泉諏訪神社慶応 4 年
http://www.wasan.jp/iwate/suwa.html

下図のように,半径 1 の円の中に 2 種類の円がありそれぞれ接している。それぞれの円の半径を求めよ。

紙と鉛筆でも求めることができる。

小さい円の半径は r2 = 1/5 である。大きい円の半径は r1 = 3*r2。右の小さい円の中心を (x, ±r2) とする。

using SymPy

@syms x::positive;

r2 = 1//5
r1 = 3r2
eq1 = x^2 + r2^2 - (1 - r2)^2
eq1 |> expand |> println

   x^2 - 3/5

solve(eq1, x)[1] |> println # x について解く

   sqrt(15)/5

using Plots

function circle(ox, oy, r, color=:red; beginangle=0, endangle=360)
   θ = beginangle:0.1:endangle
   x = r.*cosd.(θ)
   y = r.*sind.(θ)
   plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
end;

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

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   x = sqrt(15)/5
   r2 = 1/5
   r1 = 3r2
   println("r2 = $r2,  x = $x")
   plot()
   circle(0,  2r2, 3r2, :blue)
   circle(0, -2r2, 3r2, :blue)
   circle( x,  r2, r2, :green)
   circle( x, -r2, r2, :green)
   circle(-x,  r2, r2, :green)
   circle(-x, -r2, r2, :green)
   circle( 0,   0, r2, :green)
   if more
       hline!(-1:r2:1, linewidth=0.1)
       point(x, r2, "(x,r2)\n", :green, :center, :bottom)
       plot!([0, x], [0, r2], linewidth=0.5, linestyle=:dash)
   end
   circle(0, 0, 1)
end;

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

算額(その14)

2022年11月07日 | Julia

算額(その14)

山形県山形市山寺 立石寺(山寺)根本中堂 大正3年
http://www.wasan.jp/yamagata/yamadera.html

下図のように,半径 1 の円の中に 3 つの正方形がある。一番小さい正方形の一辺の長さを求めよ。

最小の正方形の一辺を a,二番目に小さい正方形の一辺をその x 倍,すなわち ax とする。

using SymPy

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

sqrt2 = sqrt(Sym(2));
eq1 = (a*x + a*sqrt2)^2 +(a*x + a/sqrt2)^2 - 1;
eq2 = (a*x)^2 + (3a*x)^2 - 1;

連立方程式を解き,r, x を求める。

res = solve([eq1, eq2], (a, x))

   1-element Vector{Tuple{Sym, Sym}}:
    (4*sqrt(5)/25, 5*sqrt(2)/8)

using Plots

function circle(ox, oy, r, color=:red; beginangle=0, endangle=360)
   θ = beginangle:0.1:endangle
   x = r.*cosd.(θ)
   y = r.*sind.(θ)
   plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
end;

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

function square(x1, y1, x2, y2, color=:green)
   plot!([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1],
         linewidth=0.5, color=color)
end

function square2(a, x, color=:magenta)
   plot!([a*(x+1/sqrt(2)), a*(x+sqrt(2)), a*(x+1/sqrt(2)), a*x, a*(x+1/sqrt(2))],
         [a*x, a*(x+1/sqrt(2)), a*(x + sqrt(2)), a*(x+1/sqrt(2)), a*x],
         linewidth=0.5, color=color)
end

function draw(more=false)
   pyplot(size=(500, 500), aspectratio=1, label="", fontfamily="IPAMincho")
   (a, x) = (4*sqrt(5)/25, 5*sqrt(2)/8)
   println("a = $a, x = $x")
   plot()
   if more
       point(0, a*x, "(0,a*x)", :blue, :right, :top)
       point(a*x, a*x, "(a*x,a*x)", :blue, :center, :top)
       point(a*x, a*x+a/√2, "(a*x,a*x+a/√2)", :blue, :right, :top)
       point(a*x+a/sqrt(2), a*x, "(a*x+a/√2)", :blue, :left, :top)
       point(0, -a*x-a*sqrt(2), "(0,-a*x-a*√2)", :blue, :center, :top)
       point(0, 3a*x, "(0,3a*x)", :blue, :center, :top)
   end
   square(-a*x - a/sqrt(2), -a*x - a*sqrt(2), a*x + a/sqrt(2), a*x, :green)
   square(-a*x, a*x, a*x, 3a*x, :brown)
   square2(a, x)
   circle(0, 0, 1)
end;

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

算額(その13)

2022年11月07日 | Julia

算額(その13)

山形県山形市山寺 立石寺(山寺)根本中堂 大正3年
http://www.wasan.jp/yamagata/yamadera.html

下図のように,正方形の中に四分円と円がある。円はそれぞれ四分円と正方形の対角線に接する。円の半径を求めよ。

正方形の一辺を 1,円の半径と中心座標を r, (x, r - 1) とする。

using SymPy

@syms r::positive, x::negative;

四分円と円が接することから

eq1 = x^2 + (r - 1)^2 - (1 + r)^2 |> expand
eq1 |> println

   -4*r + x^2

円と正方形の対角線が接することから

x2 = x - r/sqrt(Sym(2))
y2 = r - 1 + r/sqrt(Sym(2))
eq2 = r^2 + x2^2 + y2^2 - (1 + r)^2 |> expand
println(eq2)

   sqrt(2)*r^2 + 2*r^2 - sqrt(2)*r*x - 4*r - sqrt(2)*r + x^2

連立方程式を解き,r, x を求める。

res = solve([eq1, eq2], (r, x))

   1-element Vector{Tuple{Sym, Sym}}:
    ((-2 - 2*sqrt(2 - sqrt(2)) + 2*sqrt(2))^2/4, -2 - 2*sqrt(2 - sqrt(2)) + 2*sqrt(2))

using Plots

function circle(ox, oy, r, color=:red; beginangle=0, endangle=360)
   θ = beginangle:0.1:endangle
   x = r.*cosd.(θ)
   y = r.*sind.(θ)
   plot!(ox .+ x, oy .+ y, color=color, linewidth=0.5)
end;

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

function draw(more=false)
   pyplot(size=(500, 500), aspectratio=1, label="", fontfamily="IPAMincho")
   (r, x) = ((-2 - 2*sqrt(2 - sqrt(2)) + 2*sqrt(2))^2/4, -2 - 2*sqrt(2 - sqrt(2)) + 2*sqrt(2))
   println("r = $r,  x = $x")
   x2 = x - r/sqrt(2)
   y2 = r - 1 + r/sqrt(2)
   plot()
   if more
       point(x, r - 1, "(x,r-1)", :blue, :left, :top)
       point(x2, y2, "(x2,y2)", :blue, :right, :bottom)
       plot!([0, x], [0, r - 1], color=:red, linewidth=0.5, linestyle=:dash)

   end

   circle(0, 0, 1, beginangle=180, endangle=270)
   plot!([-1, 0, -1, -1, 0, 0], [-1, 0, 0, -1, -1, 0], color=:red, linewidth=0.5,
       xlims=(-1.05, 0.05), ylims=(-1.05, 0.05))
   circle(x, r - 1, r, :blue)
end;

 

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

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

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