<< Graphics`MultipleListPlot`

Lagrange's equation

Lag[
        q_] := D[D[T, q'[t]], t]-D[T, q[t]]+D[V, 
          q[t]]

example 8.5    p.185

T := (1/2) m x'[t]^2
V := (1/2) k x[t]^2

eq = Simplify[Lag[x]]

example 8.6   p.186

T := (1/2) M x'[t]^2 + (1/2) 
          m (x1'[t]^2 +  y1'[t]^2)
V := m g (l - y1[t]) + (1/2) k x[t]^2

x1[t_] := x[t] + l Sin[ϕ[t]]
y1[t] := l Cos[ϕ[t]]

eq1 = Simplify[Lag[x]]
eq2 = Simplify[Lag[ϕ]]

para1={Sin[ϕ[t]] -> ϕ[t],Cos[ϕ[t]] -> 1, ((ϕ'[t])^2)->0};
eq1 /. 
      para1
eq2 /. para1

example 8.7   p.187

T := (1/2) ii  ϕ'[t]^2 + (1/2) 
          m x'[t]^2
V := (1/2) k1 y[t]^2 + (1/2) 
          k2 ( y[t] - x[t])^2

y[t_] := r ϕ[t]

eq1 = Simplify[Lag[x]]
eq2 = Simplify[Lag[ϕ]]

additional example  3 DOF for  building mass-spring system

ClearAll[x1, x2, x3]

T := (1/2) m1 x1'[t]^2 + (1/2) m2 x2'[t]^2 + (1/2) 
          m3 x3'[t]^2
V := (1/2) k1 x1[t]^2 + (1/2) 
          k2 (x1[t] - x2[t])^2 + (1/2) 
          k3 (x2[t] - x3[t])^2

eq1 = Simplify[Lag[x1]]
eq2 = Simplify[Lag[x2]]
eq3 = Simplify[Lag[x3]]

mm = DiagonalMatrix[{m1, m2, m3}];
MatrixForm[mm]
kk = {{k1 + k2, -k2, 0}, {-k2, 
            k2 + k3, -k3}, {0, -k3, 
            k3}};
MatrixForm[kk]

dd = {x1[t], x2[t], x3[t]}

mm .  D[dd, {t, 2}] + kk . dd - {eq1, eq2, eq3}

para = {m1 ->  5, m2 ->  4, m3 ->  3, 
        k1 ->  1000,  k2 ->  750, k3 -> 500}

{eig, ϕt} = N[Eigensystem[Inverse[mm] . kk /. para]]

wn = Sqrt[eig]/2/Pi

MatrixForm[Transpose[ϕt]]

MultipleListPlot[Join[{0}, ϕt[[1]]], 
      Join[{0}, ϕt[[2]]], Join[{0}, ϕt[[3]]], 
      PlotJoined ->  True]