Bachistochrone

3946 days ago by medlock

var('a b y_a y_b t t_b C') x(t) = 1 / 2 / C * (t - sin(t)) + a y(t) = y_a - 1 / 2 / C * (1 - cos(t)) show('$x(t) = %s, \quad y(t) = %s$' % (latex(x(t)), latex(y(t)))) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{$x(t) = a + \frac{t - \sin\left(t\right)}{2 \, C}, \quad y(t) = y_{a} + \frac{\cos\left(t\right) - 1}{2 \, C}$}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{$x(t) = a + \frac{t - \sin\left(t\right)}{2 \, C}, \quad y(t) = y_{a} + \frac{\cos\left(t\right) - 1}{2 \, C}$}
# m = (y_b - y_a) / (b - a) var('m') p1 = plot([- m * (t - sin(t)) for m in srange(0, -1.5, -0.25, include_endpoint = True)], (t, -2 * pi, 2 * pi)) p2 = plot(1 - cos(t), (t, -2 * pi, 2 * pi), color = 'red') show(p1 + p2, ymin = -3, ymax = 3, axes_labels = ['$t$', '']) 
       
# Set endpoints a = 0 y_a = 0 b = 1 y_b = -1 # Find t value at right endpoint t_b = find_root((b - a) * (1 - cos(t)) + (y_b - y_a) * (t - sin(t)), 0.001, 2 * pi) # Find C value S = solve(x(t_b, a = a) == b, C, solution_dict = True) CVal = S[0][C] show('$t_b = %g, \quad C = %g$' % (t_b, CVal)) p1 = parametric_plot((x(t, a = a, C = CVal), y(t, y_a = y_a, C = CVal)), (t, 0, t_b)) p2 = points([[a, y_a], [b, y_b]], color = 'red', size = 30) show(p1 + p2, axes_labels = ['$x$', '$y$']) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{$t_b = 2.41201, \quad C = 0.872727$}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{$t_b = 2.41201, \quad C = 0.872727$}
# Set left endpoint # Essentially, this is translating X = x - a, Y = y - y_a a = 0 y_a = 0 @interact def Brachistochrone(b = slider(0, 10, 0.1, 1), y_b = slider(-10, 0, 0.1, -1)): # Find t value at left endpoint t_b = find_root((b - a) * (1 - cos(t)) + (y_b - y_a) * (t - sin(t)), 0.001, 2 * pi) # Find C value S = solve(x(t_b, a = a) == b, C, solution_dict = True) CVal = S[0][C] show('$t_b = %g, \quad C = %g$' % (t_b, CVal)) p1 = plot((x(t, a = a, C = CVal), y(t, y_a = y_a, C = CVal)), (t, 0, t_b), parametric = True) p2 = points([[a, y_a], [b, y_b]], color = 'red', size = 30) show(p1 + p2, axes_labels = ['$x$', '$y$']) 
       
y_b 

Click to the left again to hide and once more to show the dynamic interactive window