About the things that motivated Joseph Louis Lagrange:
A translation of 'Mecanique Analytique' is available on Archive.org
'
Mechanique Analytique'
The following is my interpretation
(As in: don't take my word for it, go to the original source):
The structure of 'Mecanique Analytique' is that Lagrange first sets out to cover a wide range of cases in Statics.
Let me give the simplest example (my example, I haven't looked up whether Lagrange discusses it): a marble in a bowl. The marble comes to rest at the lowest point in the bowl. For that case that is the equilibrium point.
Lagrange discusses how to set up a method that generalizes, so that for many different cases one can identify the equilibrium point. For instance, Daniel Bernoulli had proposed to give the object a small nudge (a virtual displacement), and to evaluate how much
velocity the object will gain as gravity moves it towards the equilibrium point. The equilibrium point is the point where for all nudges you obtain the same result for expected velocity. In Lagrange's time several approaches like that were in circulation.
For problems in Statics Calculus of Variations is well suited. Lagrange is credited with further development of Calculus of Variations. Lagrange did the development work on Calculus of Variations for application in Statics. For evaluation of effect of virtual displacement I think Lagrange settled on evaluating change of energy.
That said, at the time the concept of 'energy' was not in the form that we know today.
It was known, of course, that in perfectly elastic collission a quantity proportional to ##mv^2## is conserved. That quantity was named 'vis viva', the 'living force'.
This 'vis viva' is of course a precursor to our modern notion of kinetic energy. The point is: at the time the concept of 'vis viva' was a standalone concept, it was not recognized as being part of a larger conserved quantity concept.
Lagrange had a concept corresponding to what today is referred to as
potential energy, and he had the relation with
vis viva, but he did not have that in the modern form.
That is: Lagrange did not have the modern form of the Work-Energy theorem.
(Actually, I have searched hard, and I cannot find the point in time that physicists shifted to the modern form of the Work-Energy theorem. Gustave Gaspard Coriolis proposed to name the integral of force over distance 'travail' - until then that integral did not have a standard name, but the work-energy theorem is not credited to him. It appears the modern form of the Work-Energy theorem grew organically. )
Joseph Louis Lagrange: Mechanics
My interpretation is that Lagrange was keen to treat Mechanics as extending the concepts of Statics. For Statics Lagrange had already been using theory of
motion, but only for virtual displacements. My interpretation is that Lagrange wanted to merge the idea of evaluating virtual displacement with theory of Mechanics.
In modern physics textbooks this approach is often presented as applying
d'Alembert's principle.
However, when you go to the original works by d'Alembert then you find that the concept that textbook authors offer as
d'Alembert's principle is not there.
There is a set of two articles, by the historian of science Craig Fraser, with discussion of the
Traité Dynamique by d'Alembert.
http://homes.chass.utoronto.ca/~cfraser/Dalembert.pdf
http://homes.chass.utoronto.ca/~cfraser/D'Alembert2.pdf
One interpretation is that it was Lagrange who introduced the concept that today is referred to as d'Alembert's principle, and that he attributed it to d'Alembert.
On the history of concept of action
In my opinion the most interesting information is that Joseph Louis Lagrange did
not use Calculus of Variations for problems in Mechanics.
The first to apply Calculus of Variations in Mechanics was William Rowan Hamilton, his first publication on that subject was in 1834, whereas the first edition of Mecanique Analytique was published in 1789.
In Lagrange's time another action concept did already exist:
Maupertuis' action
Joseph Louis Lagrange was of the opinion that Maupertuis' action concept was not particularly relevant.
I quote from the translation of Mecanique Analytique available on Archive.org:
This principle, viewed analytically, consists of the following: in the motion of bodies which act on one another, the sum of the products of the masses with the velocities and the spaces traversed is a minimum. The author deduced from it the laws of reflection and refraction of light as well as the laws governing the percussion of bodies in two memoirs read to the Academie des Sciences of Paris in 1744 and two years later at the Academie de Berlin, respectively.
However, these applications are too restrictive to be used to establish the truth of a general principle. They have also something vague and arbitrary about them which can only make the consequence which one could draw for the accuracy of the principle itself uncertain. Thus it would be wrong, it seems to me, to put this principle as it is presented on the same level with the ones we just discussed.
Today, when people refer to
Lagrangian mechanics invariably what they have in mind is
Hamilton's stationary action.
However, that is not how Joseph Louis Lagrange approached mechanics. We do have that Lagrange was keen to have evaluation of virtual displacement as central concept. That evaluation of virtual displacement already gives rise to what we refer to as
the Lagrangian of classical mechanics: ##(E_k - E_p)##
William Rowan Hamilton
David R. Wilkins has created many, many
transcripts of Hamilton's articles, including the articles on classical mechanics. (The transcripts are easier to read than the scans of the originals
and they are machine searcheable.)
The page titled
On a general method in Dynamics is specific for giving links to Hamilton's articles on the subject of Dynamics
What today is presented as
Hamilton's principle of least action is not present in Hamilton's articles in that form. I think it is safe to say that many of the thoughts that today are attributed to Hamilton were in fact not considered by Hamilton.
In his 1834 articles, when Hamilton refers to an 'Action' concept, he is referring to Maupertuis' action. Hamilton offers the name 'Characteristic Function' for his own contribution. Also, I get the impression that Hamilton was particularly interested in a formulation where the variation that is applied is variation of the
start point and
end point of the trial trajectory. I get the impression that that is the content of the Characteristic Function that Hamilton is referring to. Of course, the modern notion of stationary action is that the start point and end point are kept fixed, but it appears that wasn't the main interest of Hamilton.
Hamiltonian mechanics
The formulation of mechanics that is referred to as
Hamiltonian mechanics relates to Lagrangian mechanics in the following way: the two are interconverted by way of Legendre transformation. One particularly relevant property of Legendre transformation is that it is its own inverse; applying Legendre transformation
twice recovers the original function. This is a general property: the various formulations of classical mechanics: Newtonian, Lagrangian, Hamiltonian, are interderivable.
I recommend the 2008 article by R. K. P. Zia, Edward F. Redish, Susan R. McKay:
Making sense of the Legrendre transform
While it is the case that when the Lagrangian is ##(E_k - E_p)## the Hamiltion ##H## coincides with the total energy, that is rather a fluke, as explained in the above linked article.
Physics textbooks
It would appear that when an author of a physics textbook writes a "historical introduction" the author recounts from memory things they read decades before in the textbook that they learned from, written by an author who also recounted from memory, etc. However, human memory is highly error prone in situations like that. Some elements are lost, other elements are added, and the story is reshaped to a form that aligns with the author's expectation.
It is important to be aware that in physics textbooks the "historical introduction" is a highly fictionalized story. That is what happens when people do not check their memory against the original sources.