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

(l = 1; J = (1/3)*l^3; (Subscript[J, S]) = (1/12)*l^3; m = l;
yS1 = (l/2)*Cos[φ1[t]];
xS2 = 
            l*Sin[φ1[t]] + (l/2)*Sin[φ2[t]];
yS2 = 
            l*Cos[φ1[t]] + (l/2)*Cos[φ2[t]];
xS3 = 
            l*Sin[φ1[t]] + 
              l*Sin[φ2[t]] + (l/2)*Sin[φ3[t]];
yS3 = 
            l*Cos[φ1[t]] + 
              l*Cos[φ2[t]] + (l/2)*Cos[φ3[t]];
xS4 = 
            l*Sin[φ1[t]] + l*Sin[φ2[t]] + 
              l*Sin[φ3[t]] + (l/2)*Sin[φ4[t]];
yS4 = 
            l*Cos[φ1[t]] + l*Cos[φ2[t]] + 
              l*Cos[φ3[t]] + (l/2)*Cos[φ4[t]];
xS2pkt = D[xS2, t];yS2pkt = D[yS2, t];
xS3pkt = D[xS3, t];yS3pkt = D[yS3, t];
xS4pkt = D[xS4, t];yS4pkt = D[yS4, t];
T=(1/2)*(J*(φ1)'[t]^2+m*xS2pkt^2+m*yS2pkt^2+(Subscript[J, S])*(φ2)'[t]^2
				  +m*xS3pkt^2+m*yS3pkt^2+(Subscript[J, S])*(φ3)'[t]^2
				  +m*xS4pkt^2+m*yS4pkt^2+(Subscript[J, S])*(φ4)'[t]^2);
V = - m*
              grav*(yS1 + yS2 + yS3 + yS4);)

L = T - V // Simplify;

(Gleichung1=D[D[L,(φ1)'[t]],t]==D[L, φ1[t]]//Simplify;
Gleichung2=D[D[L,(φ2)'[t]],t]==D[L, φ2[t]]//Simplify;
Gleichung3=D[D[L,(φ3)'[t]],t]==D[L, φ3[t]]//Simplify;
Gleichung4=D[D[L,(φ4)'[t]],t]==D[L, φ4[t]]//Simplify;)

Lsgn=Solve[{Gleichung1, Gleichung2, Gleichung3, Gleichung4},{(φ1)''[t],(φ2)''[t],(φ3)''[t],(φ4)''[t]}]//Flatten;

((φ1)'[t]=omega1; (φ2)'[t]=omega2; (φ3)'[t]=omega3; (φ4)'[t]=omega4;
φ1[t] = phi1; φ2[t] = phi2; φ3[t] = phi3; φ4[t] = phi4;)

(\(force1 = \(\(Lsgn[\([1, 2]\)] // Expand\) // Simplify\) // 
            InputForm; 
StringReplace[
          ToString[
            force1], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2"
, "omega3^2" -> "omega3*omega3", "omega4^2" -> "omega4*omega4"}]\))

(\(force2 = \(\(Lsgn[\([2, 2]\)] // Expand\) // Simplify\) // 
            InputForm; 
StringReplace[
          ToString[
            force2], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2"
, "omega3^2" -> "omega3*omega3", "omega4^2" -> "omega4*omega4"}]\))

(force3=Lsgn[[3, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              force3], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2"
, "omega3^2" -> "omega3*omega3", "omega4^2" -> "omega4*omega4"}]\))

(force4=Lsgn[[4, 2]] // Expand // Simplify // 
              InputForm;
\(StringReplace[
            ToString[
              force4], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2"
, "omega3^2" -> "omega3*omega3", "omega4^2" -> "omega4*omega4"}]\))

(\(Energy = \(\(T + V // Expand\) // FullSimplify\) // 
            InputForm; 
StringReplace[
          ToString[
            Energy], {"Sin[" -> "Math.sin(", "Cos[" -> "Math.cos(", "]" -> ")"
, "omega1^2" -> "omega1*omega1", "omega2^2" -> "omega2*omega2"
, "omega3^2" -> "omega3*omega3", "omega4^2" -> "omega4*omega4"}]\))