A ball going through this pipe was put at ##O## point with zero initial speed.At the point ##(q_x,q_y)##,the speed of the ball could be decomposed as ##(\dot{q_x},\dot{q_y})##.What's more,$${\dot{q}_y}=\tan{\theta}{\dot{q}_x}=f'(q_x)\dot{q}_x \text{ } {(1)}$$.Motion energy function is $$T=\frac{1}{2}m{{\dot{q}}_x}^2+{\frac{1}{2}}m{{\dot{q}}_y}^2$$Potential function is $$V=-mg{q_x}$$ Lagrange function $$L=T-V={\frac{1}{2}}m{{\dot{q}}_x}^2+{\frac{1}{2}}m{\dot{q_y}}^2+mg{q_x} \text{ } {(2)}$$ Substituting equation (1) into equation (2),we get$$L=\frac{1}{2}m\{1+[f'(q_x)]^2\}{{\dot{q}}_x}^2+mg{q_x}$$Now,we calculate lagrange equation$$\frac{d}{dt}(\frac{{\partial}L}{{\partial}q_x})-\frac{{\partial}L}{{\partial}{q_x}}=0$$It could be get $$m\{1+[f'(q_x)]^2\}{\ddot{q}}_x+m{\dot{q}_x}^2{f'(q_x)}{f''(q_x)}-mg=0 {(3)}$$As shown in right part of figure,at point##(q_x,q_y)## of curve,the force taking effect is ##mg\cos{\theta}##,then decomposing this force at ##q_x## direction,we get$$m{\ddot{q}_x}=mg{{\cos}^2{\theta}}=mg(1+{\tan}^2{\theta})=\frac{mg}{1+[f'(q_x)]^2} \text{ }{(4)}$$Substitubing equation (4) into equation (3),we get $$m{\dot{q}_x}^2{f'(q_x)}{f''(q_x)}=0$$

This is not reasonable.

I have no idea how to explain the last equation.Is there something wrong with my force analysis?