# Evaluating the integral in the brachistochrone problem numerically

When solving the brachistochrone problem (path of least time for a mass sliding on the path, with the path having no friction, from point A to point B), the solution curves are solved from the following equation (see for example https://www.youtube.com/watch?v=zYOAUG8PxyM&t=587s):

$$x - x_0 = \int_{y_0}^y \sqrt{\frac{y_0 - y}{C - (y_0 - y)}} dy$$

Here $$(x_0, y_0)$$ is the starting position of the mass and $$C$$ is a constant which satisfies the end position $$(x_1, y_1)$$. Typically this equation is solved analytically by the help of new variable $$\theta$$, but I'm interested in solving it numerically, as I'm trying to later solve harder versions of the brachistochrone problem which are not solvable analytically and I'm practising on this easier case first.

The brachistochrone curve is one that not only goes down but also comes up. This seems like a problem for me, because when you look at the equation above, the right-hand side always gets same value for any given value of $$\textbf{y}$$. If we take two points of brachistochrone curve which have the same y-value but different x-values (figure below), then for these points the right-hand side of the equation is the same but left-hand side isn't, which is a contradiction. Where am I making a mistake?

• Why do you expect different values of y to give the same value for x? You need to change C for that to be true. Jan 3 at 13:34
• You got x and y mixed up, but anyways as you can see in the picture above, points for which y is the same and x is different exist. And if I have understood correctly, C is a constant that I cannot change for different points Jan 3 at 13:55
• Jan 3 at 14:38

I didn't look closely into the calculations, but it seems to me like this might be the kind of problem you could encounter if you happen to treat integrals too lightheartedly: the problem of the brachistochrone is formulated in terms of the arch length, and you have to change variables in order to get a relation between $$x$$ and $$y$$. We don't usually worry much about changing variables, since we usually use the following formula: $$\int_a^bf(\varphi(x))\varphi'(x)dx=\int_{\varphi(a)}^{\varphi(b)}f(t)dt,$$ but we might want to force a substitution this way: $$\int_c^df(t)dt=\int_{\varphi^{-1}(c)}^{\varphi^{-1}(d)}f(\varphi(x))\varphi'(x)dx,$$ in which case, you can see that it becomes important whether $$\varphi$$ is injective or not: $$\varphi^{-1}$$ might not be a well defined function! I believe the video you saw might have skipped this consideration for the sake of simplicity (the search for a general solution paradoxically leaves you more freedom in taking assumptions on the details of your problem than the specific problem itself).
As the previous answer suggests, the problem lies with the fact that the y isn't an injection and thus integrating over it gives rise to the problem. I solved this by splitting the integral to two parts (from $$y_0$$ to $$y_{min}$$ and from $$y_{min}$$ to $$y$$). I found the lowest y-value $$y_{min}$$ numerically. Credit goes to the previous answer, as he helped me realize the right way to treat this problem.