LagEq[qi_,L_ ,Qi_,t_:t] := 
D[ D[L,(D[qi[t],t])],t]-D[L,qi[t]]==Qi;
  
LagEq[qi_List,L_,Qi_List,t_:t] :=
(D[ D[L,(D[qi[[#]][t],t])],t]-D[L,qi[[#]][t]]==Qi[[#]]
)&  /@  Range[1,Length[qi]];

Protect[LagEq];

Problem 1: Mass and pulley

Clear["Global`*"]

Tenergy=(1/2)m1 ((x'[t])^2) + (1/2)Inertia ((θ'[t])^2) /.{Inertia->κ m2 (r^2)}

Vpot=-m1 g  x[t] Sin[α];

Without Lagrange multiplier

constraint= r θ[t]-x[t]==0;
dsol=DSolve[constraint,θ,t][[1]]

Lag= Tenergy - Vpot /.dsol

eq1= LagEq[ x,Lag,0,t]

Solve[eq1,x''[t]][[1]]

With Lagrange multiplier

constraint= x[t] - r θ[t]==0;
constraint[[1]]

D[constraint[[1]],x[t]]

D[constraint[[1]],θ[t]]

Qlist=λ{D[constraint[[1]],x[t]],D[constraint[[1]],θ[t]]}

Lag= Tenergy - Vpot

eq1= LagEq[ {x,θ},Lag,Qlist,t]

D[constraint,{t,2}]

θsol=Solve[ D[constraint,{t,2}],θ''[t]][[1]]

eq2=eq1 /.θsol

Solve[eq2,{x''[t],λ}][[1]]