x1 := L Sin[ϕ[t]];
y1 := -L Cos[ϕ[t]];

    
x2 := 
        l Sin[ϕ[t] + ψ[t]]  +  x1;
y2 := -l Cos[ϕ[t] + ψ[t]] + 
          y1;

    
T1 := ((M )/2) (D[x1, t]^2 + 
              D[y1, t]^2);
V1 := M g y1;

    
T2 := 
        (m/2)  (D[x2, t]^2 + D[y2, t]^2);
V2 := 
        m g y2  ;


Lagrange = 
        T1 - V1 + T2 - V2 // 
          FullSimplify;

  
H = 
      (Subscript[p, ϕ])[t] (∂_t) ϕ[t] +  
          (Subscript[p, ψ])[t] (∂_t) ψ[t] - Lagrange  // 
        FullSimplify

(* Die Hamilton' 
        schen Bewegungsgleichungen *) 

(Subscript[p, ϕ])'[
        t] = -(∂_(ϕ[t]))H // 
        FullSimplify
(Subscript[p, ψ])'[t] = -(∂_(ψ[t]))H // 
        FullSimplify
ϕ'[
        t] = (∂_((Subscript[p, ϕ])[t]))H
ψ'[t] = (∂_((Subscript[p, ψ])[t]))H