Updates : 2018

********************************
Initialization:

Off[General::spell];
Off[General::spell1];

Clear["Global`*"]

********************************
Atwood Machine: simple 1 variable:

Clear["Global`*"]

f[1]=x[1][t]+x[2][t]-L1

sol= DSolve[f[1]==0,x[2],t][[1]]

We use DSolve so that we also substitute for derivatives of x[2]; Solve  won' t work for this. (Try it!)

{x[2][t],x[2]'[t],x[2]''[t]} /.sol

T= (1/2) Sum[m[i] D[x[i][t],t]^2 ,{i,1,2}] //.sol //Simplify

V= (- g) Sum[  m[i] x[i][t] ,{i,1,2}] //.sol

L=T-V

Clear[Q];
Q[i_]:=0

D[L,(x[1])[t]]

D[L,(x[1])'[t]]

D[ D[L,(x[1])'[t]] ,t]

Lagrangian[i_]:=(
   D[ D[L,(x[i])'[t]] ,t] 
   - D[L,x[i][t]] == Q[i]
 )

eqs= Lagrangian[1] //Simplify

sol3= DSolve[eqs ,{x[1]},t] //First //Simplify

eqs //.sol3 //Simplify

initial={x[1][0]==x0, x[1]'[0]==v0};
eqs2=Join[{eqs},initial]

sol4= DSolve[eqs2 ,{x[1]},t]//First //Simplify

x[1][t] /.sol4

x[1][t] /.sol4 //Simplify

Collect[%,g]

eqs2 //.sol4 //Simplify

********************************
Atwood Machine: simple 2 variable

Clear["Global`*"]

T= (1/2) Sum[m[i] D[x[i][t],t]^2 ,{i,1,2}]

V= (- g) Sum[  m[i] x[i][t] ,{i,1,2}]

f[1]=x[1][t]+x[2][t]-L1

L=T-V

Q[i_]:=Sum[ D[f[j],x[i][t]] lambda[j] ,{j,1,1}]

Table[Q[i],{i,1,2}]

Lagrangian[i_]:=(
   D[ D[L,(x[i])'[t]] ,t] 
   - D[L,x[i][t]] == Q[i]
 )

eq1= Table[Lagrangian[i],{i,1,2}];
eq1  //TableForm

eq2=D[f[1],{t,2}]==0

sol1=Solve[eq2,(x[2])''[t],t][[1]]

eq2= eq1 //.sol1;
eq2 //TableForm

eq3=Eliminate[eq2,lambda[1]]

initial={x[1][0]==x0, x[1]'[0]==v0};
eq4=Join[{eq3},initial]

sol2= DSolve[eq4,{x[1]},t][[1]]

eq5=eq2 /.sol2

Solve[eq5[[1]],lambda[1]][[1]]

x[1][t] /.sol2 //Simplify //Collect[#,g]&

x2Sol=DSolve[f[1]==0,{x[2]},t]

tmp= x[2][t] /.x2Sol /.sol2 //FullSimplify //Collect[#, t]&

MapAt[Together,tmp,{1,4}]

x[1][t] /.sol2 //Simplify //Collect[#,g]&

********************************
Atwood Machine: 4 masses

Clear["Global`*"]

2.	An Atwood machine is built as follows:  A string of length L1 passes over a fixed light pulley supporting a mass m1 on one end and a pulley of mass m2 (negligible moment of inertia) on the other.  Over this second pulley passes a string of length L2 supporting a mass m3 on one end and m4 on the other where m3 =/=  m4.  Set up Lagrange's equations for this system using the method of Lagrange multipliers.  Use as coordinates the (not independent) distances of the four masses from the fixed pulley.  Solve for the two forces of constraint and show that the mass m1 remains in equilibrium if:

m1 = m2 + m3 + m4  - (m4-m3)^2/(m4+m3)

T= (1/2) Sum[m[i] D[x[i][t],t]^2 ,{i,1,4}]

V= (- g) Sum[  m[i] x[i][t] ,{i,1,4}]

f[1]=x[1][t]+x[2][t]-L1

f[2]=x[3][t]+x[4][t]-2 x[2][t] -L2

L=T-V

Q[i_]:=Sum[ D[f[j],x[i][t]] lambda[j] ,{j,1,2}]

Array[Q,4]

Lagrangian[i_]:=(
   D[ D[L,(x[i])'[t]] ,t] 
   - D[L,x[i][t]] == Q[i]
 )

eqs= Table[Lagrangian[i],{i,1,4}]

eqs2={(x[1])''[t]            == - (x[2])''[t],
      (x[3])''[t]+(x[4])''[t]== 2 (x[2])''[t]
     };

sol=Solve[eqs2,{(x[1])''[t],(x[2])''[t]}][[1]]

eqs3= eqs //.sol

sol2= DSolve[eqs3[[{3,4}]] ,{x[3],x[4]},t][[1]]

sol3= Solve[(eqs3[[{1,2}]] //.sol2 //Simplify)
        ,{lambda[1],lambda[2]}][[1]] //Simplify

tmp= x[1]''[t] /.sol /.sol2 /.sol3 //FullSimplify

tmp /.sol7

Do again, but with (x[1])''[t]==0 s.t. m[1] is in equlibrium.

eqs4={(x[1])''[t]            == 0,
      (x[1])''[t]            == - (x[2])''[t],
      (x[3])''[t]+(x[4])''[t]== 2 (x[2])''[t]
     };

sol4=Solve[eqs4,{(x[1])''[t],(x[2])''[t],(x[3])''[t]}][[1]]

eqs5= eqs //.sol4

sol5= DSolve[eqs5[[{4}]] ,{x[4]},t][[1]]

(eqs5[[{1,2,3}]] //.sol5 //Simplify)

sol6= Solve[(eqs5[[{1,2}]] //.sol4 //Simplify)
        ,{lambda[1],lambda[2]}][[1]] //Simplify

eqs6=eqs5  //.sol5 //.sol6 //ExpandAll

sol7=Solve[ eqs6[[3]],m[1] ][[1]] //Simplify