裏 RjpWiki

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

算額(その508)

2023年11月24日 | Julia

算額(その508)

秋田県仙北市角館町西長野 熊野神社 嘉永2年(1849)
http://www.wasan.jp/akita/kakunodatekumano1.html
小寺裕: 算額あれこれ
秋月めぐる,遠藤寛子: 算法少女(1),リイド社,2013.

鈎股弦(直角三角形内)に二等辺三角形と 2 個の正方形が入っている。鈎の長さが 1 のとき,股の長さはいかほどか。
原点と (x,y) を結ぶ線分は,弦と直交する。

図のように記号を定め,連立方程式の数値解を求める。

include("julia-source.txt");

using SymPy
@syms 鈎::positive, 股::positive, 弦::positive, x::positive, y::positive, x2::positive, y2::positive

eq1 = y/(股 - x) - 鈎/股
eq2 = 股*鈎 - 弦*sqrt(x^2 + y^2)
eq3 = 2(x - x2) - y2
eq4 = y2/(股 - 2x -y2) - 鈎/股
eq5 = 鈎^2 + 股^2 - 弦^2
eq6 = y/x - y2/x2;
res = solve([eq1, eq2, eq3, eq4, eq5, eq7], (股, 弦, x, y, x2, y2))

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 v, r.f_converged
end;

function H(u)
   (股, 弦, x, y, x2, y2) = u
   return [
       y/(-x + 股) - 鈎/股,  # eq1
       -弦*sqrt(x^2 + y^2) + 股*鈎,  # eq2
       2*x - 2*x2 - y2,  # eq3
       y2/(-2*x - y2 + 股) - 鈎/股,  # eq4
       -弦^2 + 股^2 + 鈎^2,  # eq5
       -y2/x2 + y/x,  # eq6
   ]
end;

鈎 = 1
iniv = BigFloat[2.0, 2.2, 0.2, 0.8, 0.1, 0.5]
res = nls(H, ini=iniv)

   (BigFloat[1.999999999999999999985926409326636355492543560353991554111136639959569147152117, 2.236067977499789696396585866558016976252953289080026164208793498254395925337324, 0.3999999999999999999976356367668749077227473181394705810906711610880915130403816, 0.7999999999999999999997748225492261816878806969656638648657781909543976392427267, 0.1999999999999999999982548747565029080810754014838949527097809876602829734671478, 0.3999999999999999999987615240207439992833438333111512567617803468556170791464633], true)

   股 = 2;  弦 = 2.23607;  x = 0.4;  y = 0.8;  x2 = 0.2;  y2 = 0.4

鈎の長さが 1 のとき,股の長さは 2 である。

using Plots

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   (股, 弦, x, y, x2, y2) = res[1]
   @printf("股 = %g;  弦 = %g;  x = %g;  y = %g;  x2 = %g;  y2 = %g\n", 股, 弦, x, y, x2, y2)
   plot([0, 股, 0, 0], [0, 0, 鈎, 0], color=:black, lw=0.5)
   rect(x2, 0, x2 + y2, y2, :red)
   rect(2x, 0, 2x + y2, y2, :red)
   plot!([0, x, 2x], [0, y, 0], color=:blue, lw=0.5)
   if more
       delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3  # size[2] * fontsize * 2
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
       point(x, y, "(x,y)", :blue, :left, :bottom, delta=delta)
       point(2x, 0, " 2x", :blue, :left, :bottom, delta=delta)
       point(x2, y2, " (x2,y2)", :red, :left, :bottom, delta=delta)
       point(2x + y2, y2, " (2x+y2,y2)", :red, :left, :bottom, delta=delta)
       point(股, 0, "股", :black, :left, :bottom, delta=delta)
       point(0, 鈎, " 鈎", :black, :left, :bottom, delta=delta/2)
   else
       plot!(showaxis=false)
   end
end;

 

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

算額(その507)

2023年11月24日 | Julia

算額(その507)

長岡高専和算倶楽部オリジナル算額
山田 章,谷口 悠,加藤 祐樹,長谷川 柊太,平田 大成,中山 雅友美,冨樫 瑠美,涌田 和芳: 長岡高専和算倶楽部オリジナル算額について,長岡工業高等専門学校研究紀要,57 巻,p. 41-45,2021.
https://kinpoku.nagaoka-ct.ac.jp/lib/kiyo/vol_57/57_41yamada.pdf

正三角形に内接する正方形(正方形の3つの頂点が正三角形の 3 つの辺上にある)の一辺の長さが最小になるのはどのようなときか。

正三角形の一辺の長さを a,正方形の一辺の長さを b とする。
正方形の 4 つの頂点座標を (x1, 0 ), (x2, y2), (x3, y3), (x4, y4) とする。
(x1, 0), (x2, y2) を結ぶ線分が正三角形の底辺となす角を θ° として,
以下の連立方程式を解く。

include("julia-source.txt");

using SymPy
@syms a, b, θ, x1, x2, y2, x3, y3, x4, y4

x2 = x1 + b*cosd(θ)
y2 =      b*sind(θ)
x3 = x2 - b*sind(θ)
y3 = y2 + b*cosd(θ)
x4 = x1 - b*sind(θ)
y4 =      b*cosd(θ)

eq1 = y4/x4 - sqrt(Sym(3))
eq2 = y3/(a - x3) - sqrt(Sym(3))
res = solve([eq1, eq2], (x1, b))

   Dict{Any, Any} with 2 entries:
     b  => sqrt(3)*a/(2*(sin(pi*(θ/180 + 1/3)) + cos(pi*θ/180)))
     x1 => a*sin(pi*(θ/180 + 1/6))/(sin(pi*(θ/180 + 1/3)) + cos(pi*θ/180))

正方形の一辺の長さは sqrt(3)/(2*(sin(pi*(θ/180 + 1/3)) + cos(pi*θ/180))) である。
0 ≦ θ ≦ 30 で図を描くと以下のようになる。

using Plots
pyplot(size=(400, 200), grid=false, aspectratio=:none, label="", fontfamily="IPAMincho")
plot(res[b]/a, xlims=(0, 30), xlabel="θ", ylabel="b")

b の式の導関数を求め,導関数 = 0 となる θ を求め,そのときの b の値を求める。
正三角形の一辺の長さを a とすれば,θ が 15° のとき,正方形の一辺の長さは最小値 (3√2 - √6)a/4 = 0.448287736084027a になる。

solve(diff(res[b]/a))[1] |> println

   15

eq = (res[b])(θ => 15) |> simplify
eq |> println
eq(θ => 15).evalf() |> println

   -sqrt(6)*a/4 + 3*sqrt(2)*a/4
   0.448287736084027*a

   a = 1;  θ = 15;  x1 = 0.366025;  b = 0.448288

using Plots

function draw(more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   a = 1
   θ = 15
   b  = sqrt(3)*a/(2*(sin(pi*(θ/180 + 1/3)) + cos(pi*θ/180)))
   x1 = a*sin(pi*(θ/180 + 1/6))/(sin(pi*(θ/180 + 1/3)) + cos(pi*θ/180))
   @printf("a = %g;  θ = %g;  x1 = %g;  b = %g\n", a, θ, x1, b)
   plot([0, a, a/2, 0], [0, 0, √3*a/2, 0], color=:black, lw=0.5)
   x2 = x1 + b*cosd(θ)
   y2 =      b*sind(θ)
   x3 = x2 - b*sind(θ)
   y3 = y2 + b*cosd(θ)
   x4 = x1 - b*sind(θ)
   y4 =      b*cosd(θ)
   plot!([x1, x2, x3, x4, x1], [0, y2, y3, y4, 0], color=:blue, lw=0.5)
   if more
       delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3  # size[2] * fontsize * 2
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
       point(x1, 0, "(x1,0) ", :blue, :right, :bottom, delta=delta/2)
       point(x2, y2, "(x2,y2)", :blue, :left, delta=-delta/2)
       point(x3, y3, " (x3,y3)", :blue, :left, :vcenter)
       point(x4, y4, " (x4,y4)", :blue, :left, delta=-delta/2)
       point(a/2, √3a/2, " (a/2, √3a/2)", :black, :left, :vcenter)
       point(a, 0, "a", :black, :left, :bottom, delta=delta/2)
   else
       plot!(showaxis=false)
   end
end;

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

算額(その506)

2023年11月24日 | Julia

算額(その506)

兵庫県伊丹市 猪名野神社 嘉永6年(1853)
http://www.wasan.jp/hyogo/inano.html
宮崎興二: ある異国人の見た算額,和算,第20号,昭和53年1月1日発行
http://www.wasan.jp/kinkikaisi/wasan020.pdf

正方形内に 5 個の等円が入っている。正方形の一辺の長さが与えられたとき,等円の直径はいかほどか。

正方形の一辺の長さを a,等円の半径を r として,以下の方程式を解く。

include("julia-source.txt");

using SymPy
@syms a, x, r
x = a/2
eq1 = (x - r)^2 + (2x - r - 3r)^2 - (2r)^2
res = solve(eq1, r)[1]
res |> println

   5*a/26

等円の半径は正方形の一辺の長さの 5/26 倍である。
正方形の一辺の長さが 26 のとき,等円の直径は 10 である。

using Plots

function draw(a, more=false)
   pyplot(size=(500, 500), grid=false, aspectratio=1, label="", fontfamily="IPAMincho")
   r = 5a/26
   @printf("a = %g;  r = %g\n", a, r)
   @printf("等円の直径 = %g\n", 2r)
   plot([0, a, a, 0, 0], [0, 0, a, a, 0], color=:black, lw=0.5)
   circle(r, r, r)
   circle(r, 3r, r)
   circle(a - r, r, r)
   circle(a - r, 3r, r)
   circle(a/2, a - r, r)
   if more
       delta = (fontheight = (ylims()[2]- ylims()[1]) / 500 * 10 * 2) /3  # size[2] * fontsize * 2
       hline!([0], color=:black, lw=0.5)
       vline!([0], color=:black, lw=0.5)
       point(r, r, "(r,r)")
       point(r, 3r, "(r,3r)")
       point(a - r, r, "(a-r,r)")
       point(a - r, 3r, "(a-r,3r)")
       point(a/2, a - r, "(a/2,a-r)")
       point(0, a, " a", :green, :left, :bottom, delta=delta/2)
       point(a, 0, " a", :green, :left, :bottom, delta=delta/2)
   else
       plot!(showaxis=false)
   end
end;

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

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

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