# Frictionless motion along a surface defined by a function

I have recently been learning Lagrangian Mechanics and wanted to apply it to a case I came up with in my head. Say you have a function f(x) that is always > 0. If a box or some solid particle was moving through space along that function, how would you describe the motion? I designed the model so that the particle originated at a $y_o$ with an initial velocity in x of $\dot {x}$ and in y of $\dot y$. With this system, the Lagrangian would be

$$L = U-T = (y_o + y)mg - \frac{1}{2}m(\dot{x}^2 + \dot{y}^2)$$ *assuming that $y=0$ is $U=0$.

This yields the results of $m\ddot{x}=0$ and $\ddot{y} = -g$. This would describe a projectile, but doesn't make sense for my model, am I missing something about Lagrangian Mechanics as a whole, or have I made a mathematical mistake?

A quick note - you've written the Lagrangian as $L=U-T$. This is actually fine, because multiplying the Lagrangian by a constant doesn't change the equations of motion, but conventionally most people say that $L=T-U$. As I said, this doesn't change anything, but it's something to be aware of.

A particle moving on the graph of your function would be subject to the constraint that $$y = f(x)$$ so your problem has only a single degree of freedom - the coordinate $x$. The vertical component of the velocity would be given by $$\dot y = f'(x) \dot x$$ via the chain rule, and the Lagrangian would become $$L= \frac{1}{2}m[1+f'^2(x)]\dot x^2$$

From here, you should be able to get the equations of motion for a free particle. If you wanted to add a gravitational interaction, you would simply write

$$L=\frac{1}{2}m[1+f'^2(x)]\dot x^2 - mgf(x)$$