裏 RjpWiki

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

算額(その228)

2023年05月13日 | Julia

算額(その228)

冲方丁の「天地明察」中で,金王八幡神社に奉納されたという算額。実際には渋川春海が算額を奉納したという記録はないそうだ。

鉤が 9寸,股が 12寸の鉤股弦に等円を2個図のように入れる。円の径はいくつか。

等円の半径を r とする。
左上の等円の中心座標を (r, y)
右下の等円の中心座標を (x, r)
とおき,以下の方程式を解く。

using SymPy

function distance(x1, y1, x2, y2, x0, y0)
   p1, p2 = sympy.Point(x1, y1), sympy.Point(x2, y2)
   l = sympy.Line(p1, p2)
   l.distance(sympy.Point(x0, y0))^2  # 二乗距離を返す!!
end;

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

eq1 = (x - r)^2 + (y - r)^2 - 4r^2
eq2 = distance(0, 9, 12, 0, r, y) - r^2  # 弦への二乗距離
eq3 = distance(0, 9, 12, 0, x, r) - r^2  # 弦への二乗距離

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

   2-element Vector{Tuple{Sym, Sym, Sym}}:
    (15/7, 39/7, 33/7)
    (90/17, 234/17, 198/17)

2 番めの解が妥当なものである。すなわち等円の半径は 15/7,直径は 30/7 である。

   r = 2.1428571,  x = 5.5714286;  y = 4.7142857

「天地明察」では,「勾股を掛け合わせ,これを二倍し,勾股弦の総和で割り,弦を掛け,勾股の和で割る」術が述べられている。SymPy では以下のようになる。

using SymPy
@syms 勾, 股
(勾, 股) = (9, 12)
弦 = Int(sqrt(勾^2 + 股^2))
2鉤*股//(鉤 + 股 + 弦)*弦//(鉤 + 股)

30/2

using Plots
using Printf

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=:top; mark=true)
   mark && scatter!([x], [y], color=color, markerstrokewidth=0)
   annotate!(x, y, text(string, 10, position, color, vertical))
end;

function draw(more)
    pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (r, x, y) = res[1]
   @printf("r = %.7f,  x = %.7f;  y = %.7f\n", r, x, y)
   plot([0, 12, 0, 0], [0, 0, 9, 0], color=:blue, lw=0.5)
   circle(r, y, r)
   circle(x, r, r)
   if more == true
       point(0, 9, " 9", :blue, :left, :bottom)
       point(12, 0, " 12", :green, :left, :bottom)
       point(r, y, "(r,y)", :red)
       point(x, r, "(x,r)", :red)
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
   else
       plot!(showaxis=false)
   end
end;


コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« 算額(その227) | トップ | 算額(その229) »
最新の画像もっと見る

コメントを投稿

Julia」カテゴリの最新記事