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

(T= (1/2)*m*(x1'[t]^2+x2'[t]^2);
V= (1/2)*Federk1*((l - (Sqrt[x1])[t]^2)^2 + (l - (Sqrt[(1 - x2[t])])^2)^2)+(1/2)*Federk2*(l - (Sqrt[(x2[t] - x1[t])])^2)^2;
L = T - V;)

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

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

x1[t] = x1;x1'[t]=x1p;x2[t] = x2;x2'[t]=x2p;

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

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

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