- Ben

# Solving the Brachistochrone with PyTorch

Updated: Apr 29, 2019

__The brachistochrone problem__ is simple to explain. Imagine a bead which is free to slide on a wire. What shape of wire will get the bead from point A to point B in the shortest time? If you're wondering about the name, "brachistochrone" apparently means "shortest time" in Ancient Greek. Makes sense. The image below shows the optimal path in red, along with some slower paths in blue.

This was inspired by __Declan__, who was using this problem to learn about genetic algorithms. The problem can be solved with calculus, but I decided to approach this problem with gradient descent using PyTorch. It seemed like a natural solution, and a good way to learn about Torch. The image below shows my optimization approaching the shape of the known cycloid solution in blue.

I divided the wire into segments with heights yᵢ and calculated the speed at each segment using the height difference from the starting point. Then I found the length of the segments using the height differences between points. I calculated the time to reach each point, tᵢ, by integrating the segment length divided by the speeds. Finally, I used automatic differentiation to find the derivatives dtᵢ/dyⱼ and used gradient descent to minimize the time to reach the final point, tₗₐₛₜ.