Skip to content

Commit 1e77d25

Browse files
beachdwellerclaude
andcommitted
feat : add ipywidgets interactive bisection exploration to 10/20
Add slider widget (0–30 iterations) showing how the bisection bracket narrows around sqrt(10). Yellow band, vertical lines for x_L / x_U, and red square for x_m update in real time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bc8bc7f commit 1e77d25

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

10_root_finding/20_bisection.ipynb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,23 @@
356356
"\n"
357357
]
358358
},
359+
{
360+
"cell_type": "markdown",
361+
"source": "### 동적 탐색<br>Interactive Exploration\n\n반복 횟수를 바꾸어 가며 구간이 어떻게 좁아지는지 관찰해 보자.<br>\nChange the number of iterations and observe how the interval narrows down.",
362+
"metadata": {}
363+
},
364+
{
365+
"cell_type": "code",
366+
"source": "from ipywidgets import interact, IntSlider\n\ndef plot_bisection(iterations):\n x_l, x_u = 0.0, 6.0\n\n # 이분법 반복\n # Bisection iterations\n for k in range(iterations):\n x_m = (x_l + x_u) * 0.5\n if f(x_u) * f(x_m) < 0:\n x_l = x_m\n elif f(x_l) * f(x_m) < 0:\n x_u = x_m\n else:\n break\n\n x_m = (x_l + x_u) * 0.5\n\n # f(x) 곡선\n # f(x) curve\n x_plot = py.linspace(0, 6, 200)\n py.plot(x_plot, f(x_plot), 'k-', label='$f(x)=x^2-10$')\n py.axhline(y=0, color='r', linestyle='--', alpha=0.5)\n\n # 현재 구간 표시\n # Show current interval\n py.axvline(x=x_l, color='blue', linestyle='--', alpha=0.7, label=f'$x_L$ = {x_l:.6f}')\n py.axvline(x=x_u, color='green', linestyle='--', alpha=0.7, label=f'$x_U$ = {x_u:.6f}')\n py.axvspan(x_l, x_u, alpha=0.15, color='yellow')\n\n # 중점 표시\n # Show midpoint\n py.plot(x_m, f(x_m), 'rs', markersize=10, label=f'$x_m$ = {x_m:.6f}')\n\n interval = x_u - x_l\n py.title(f'Iteration {iterations}, Interval = {interval:.6f}, f($x_m$) = {f(x_m):.2e}')\n py.xlabel('x')\n py.ylabel('f(x)')\n py.legend(loc='upper left')\n py.grid(True)\n py.show()\n\ninteract(plot_bisection, iterations=IntSlider(min=0, max=30, step=1, value=0,\n description='Iterations:'));",
367+
"metadata": {},
368+
"execution_count": null,
369+
"outputs": []
370+
},
371+
{
372+
"cell_type": "markdown",
373+
"source": "반복 횟수를 0에서 30까지 바꾸어 보자. 구간의 폭과 $f(x_m)$이 어떻게 줄어드는가?<br>\nTry changing the number of iterations from 0 to 30. How do the interval width and $f(x_m)$ decrease?",
374+
"metadata": {}
375+
},
359376
{
360377
"cell_type": "markdown",
361378
"metadata": {},

0 commit comments

Comments
 (0)