zhouhao said:
You are right.I must misunderstand something.
Lagrangian function:##L=\frac{1}{2}m{\dot{q}_x}^2+\frac{1}{2}m{\dot{q}_y}^2+\frac{1}{2}m{\dot{q}_z}^2+mgq_x\ \ \ \ \ (1)##
Energy conservation condition:##mgq_x=\frac{1}{2}m{\dot{q}_x}^2+\frac{1}{2}m{\dot{q}_y}^2+\frac{1}{2}m{\dot{q}_z}^2\ \ \ (2.1)## and ##mg\delta{q_x}=m\dot{q}_x\delta{\dot{q}_x}+m\dot{q}_y\delta{\dot{q}_y}+m\dot{q}_z\delta{\dot{q}_z} \ \ \ \ (2.2)##
In my imagination,##\frac{\partial{L}}{\partial{q}_i}-\frac{d}{dt}\frac{\partial{L}}{\partial{\dot{q}_i}}=0## make ##\delta\int_{t_1}^{t_2}Ldt=0##
Yes, this is correct if the ##\delta## symbol means to vary the paths such that the initial and final times (##t_1## and ##t_2##) are kept fixed for all paths. For this type of path variation, the energy ##W## generally will not be conserved (except for the true path).
Equation ##(2.2)## make ##\delta\int_{t_1}^{t_2}Wdt=0##
Here, you are assuming the energy ##W## remains constant for the varied paths. So, here you are using a different type of path variation than before. So, it might be good to use a different symbol ##\Delta## for this type of path variation. For this type of variation, you must allow the endpoint times ##t_1## and/or ##t_2## to vary as you vary the path.
[EDIT: So, ##\Delta\int_{t_1}^{t_2}Wdt \neq 0## if you are varying paths keeping ##W## constant. Rather, you can see that you would get ##\Delta\int_{t_1}^{t_2}Wdt = W \Delta t_2 - W \Delta t_1##, where ##\Delta t_2## is the variation in the upper time limit when varying the path. Similarly for ##\Delta t_1##.]
So ##\delta\int_{t_1}^{t_2}(L+W)dt=0##
Here it looks like you are not considering that the two types of variation are different. [EDIT: From what I wrote above, this equation does not follow.]
But equation ##(2.1)## would make ##L=2mgq_x \ \ \ (3)##,
##\frac{\partial{L}}{\partial{q}_i}-\frac{d}{dt}\frac{\partial{L}}{\partial{\dot{q}_i}}=0## is not right argument for equation (3) now.
Lagrange's equations ##\frac{\partial{L}}{\partial{q}_i}-\frac{d}{dt}\frac{\partial{L}}{\partial{\dot{q}_i}}=0## assume that you are expressing ##L## as a function of both the ##q_i## and the ##\dot{q}_i## according to ##L = T - V##.
It seems that energy conservation condition make ##\delta\int_{t_1}^{t_2}Ldt=\int_{t_1}^{t_2}2mg\delta{q}_xdt\ne0##
The variation of the paths on the left side of the equation are the ##\delta## type of variation where energy is not conserved for the varied paths. But the integral involving ##2mg## assumes energy is conserved in the variation.
A careful discussion of going from Hamilton's principle to Maupertuis' principle can be found in Goldstein's
Mechanics, 3rd edition, starting on page 356. The text uses the ##\delta## versus ##\Delta## notation to distinguish the types of variation of path.