裏 RjpWiki

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

算額(その46)

2022年12月06日 | Julia

算額(その46)

大阪府茨木市 井於神社 弘化3年
http://www.wasan.jp/osaka/iyo.html

円の下半分に垂直方向に等間隔の弦を引く。弦の長さを求めよ。

下図のように記号を定め解を求める。


using SymPy
@syms y(), x, y;
@syms R::positive;
@syms x1::positive, x2::positive, x3::positive;

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

function answer(more)
   R = 8  # 直径
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   p = plot()
   circle(0, 0, R/2)
   y = -sqrt((R//2)^2 - x^2)  # SymPy での関数定義(円の下半分)
   for i in 0:4
       y1 = -i*(4//5)  # 弦の y 座標
       eq1 = y - y1    # 方程式
       x1, x2 = solve(eq1, x)  # 円との交点
       println("$(i+1)番: $eq1;  x1 = $x1;  x2 = $x2;  長さ = $(2*x2.evalf())")
       plot!([x1, x2], [y1, y1])
       if more && i == 3
           point(x1, y1, "x1 ", :green, :right)
           point(x2, y1, " x2", :green, :left)
       end
   end
   savefig("fig1.png")
end
answer(true)

   1番: -sqrt(16 - x^2);  x1 = -4;  x2 = 4;  長さ = 8.00000000000000
   2番: 4/5 - sqrt(16 - x^2);  x1 = -8*sqrt(6)/5;  x2 = 8*sqrt(6)/5;  長さ = 7.83836717690617
   3番: 8/5 - sqrt(16 - x^2);  x1 = -4*sqrt(21)/5;  x2 = 4*sqrt(21)/5;  長さ = 7.33212111192934
   4番: 12/5 - sqrt(16 - x^2);  x1 = -16/5;  x2 = 16/5;  長さ = 6.40000000000000
   5番: 16/5 - sqrt(16 - x^2);  x1 = -12/5;  x2 = 12/5;  長さ = 4.80000000000000

算額では 2 番が 7寸8分6厘1毛,3 番が 7寸,,2毛となっているが,それぞれ 7.838, 7.332 である。

 


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

コメントを投稿

Julia」カテゴリの最新記事