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

(T= (1/2)*(m1*(x1'[t]^2+y1'[t]^2)+m2*(x2'[t]^2+y2'[t]^2));
V=(1/2)*Federk*((l - (Sqrt[x1[t]^2 + y1[t]^2]))^2 + (l - (Sqrt[(x2[t] - x1[t])^2 + (y2[t] - y1[t])^2]))^2 + (l - (Sqrt[(1 - x2[t])^2 + y2[t]^2]))^2)-grav*(m1*y1[t] + m2*y2[t]);
L = T - V;)

(Gleichung1=D[D[L,x1'[t]],t]==D[L, x1[t]]//Simplify;
Gleichung2=D[D[L,y1'[t]],t]==D[L, y1[t]]//Simplify;
Gleichung3=D[D[L,x2'[t]],t]==D[L, x2[t]]//Simplify;
Gleichung4=D[D[L,y2'[t]],t]==D[L, y2[t]]//Simplify;)

Lsgn=Solve[{Gleichung1, Gleichung2, Gleichung3, Gleichung4},{x1''[t],y1''[t],x2''[t],y2''[t]}]//Flatten//Simplify;

(x1[t] = x1; y1[t] = y1;x1'[t]=x1p;y1'[t]=y1p;
x2[t] = x2; y2[t] = y2;x2'[t]=x2p;y2'[t]=y2p;)

(forcex1=Lsgn[[1, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              forcex1], {"x1^2" -> "x1*x1", "y1^2" -> "y1*y1", "x2^2" -> "x2*x2", "y2^2" -> "y2*y2"
, "(x1 - x2)^2" -> "(x1 - x2)*(x1 - x2)", "(y1 - y2)^2" -> "(y1 - y2)*(y1 - y2)"
, "Federk" -> "D", "Sqrt[" -> "Math.sqrt(", "]" -> ")"}]\))

(forcey1=Lsgn[[2, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              forcey1], {"x1^2" -> "x1*x1", "y1^2" -> "y1*y1", "x2^2" -> "x2*x2", "y2^2" -> "y2*y2"
, "(x1 - x2)^2" -> "(x1 - x2)*(x1 - x2)", "(y1 - y2)^2" -> "(y1 - y2)*(y1 - y2)"
, "Federk" -> "D", "Sqrt[" -> "Math.sqrt(", "]" -> ")"}]\))

(forcex2=Lsgn[[3, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              forcex2], {"x1^2" -> "x1*x1", "y1^2" -> "y1*y1", "x2^2" -> "x2*x2", "y2^2" -> "y2*y2"
, "(x1 - x2)^2" -> "(x1 - x2)*(x1 - x2)", "(y1 - y2)^2" -> "(y1 - y2)*(y1 - y2)"
, "(-1 + x2)^2" -> "(-1 + x2)*(-1 + x2)"
, "Federk" -> "D", "Sqrt[" -> "Math.sqrt(", "]" -> ")"}]\))

(forcey2=Lsgn[[4, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              forcey2], {"x1^2" -> "x1*x1", "y1^2" -> "y1*y1", "x2^2" -> "x2*x2", "y2^2" -> "y2*y2"
, "(x1 - x2)^2" -> "(x1 - x2)*(x1 - x2)", "(y1 - y2)^2" -> "(y1 - y2)*(y1 - y2)"
, "(-1 + x2)^2" -> "(-1 + x2)*(-1 + x2)"
, "Federk" -> "D", "Sqrt[" -> "Math.sqrt(", "]" -> ")"}]\))

(\(Energy = \(\(T + V // Simplify\) // Expand\) // 
            InputForm; 
StringReplace[
          ToString[
            Energy], {"l^2" -> "l*l"
, "x1p^2" -> "x1p*x1p", "y1p^2" -> "y1p*y1p"
, "x2p^2" -> "x2p*x2p", "y2p^2" -> "y2p*y2p"
, "x1^2" -> "x1*x1", "y1^2" -> "y1*y1"
, "x2^2" -> "x2*x2", "y2^2" -> "y2*y2"
, "(x1 - x2)^2" -> "(x1 - x2)*(x1 - x2)"
, "(y1 - y2)^2" -> "(y1 - y2)*(y1 - y2)"
, "Federk" -> "D", "Sqrt[" -> "Math.sqrt(", "]" -> ")"}]\))