Spring mass with control function

Hi Guys, really need help.
I putting the system response here and the animation code.
So my question is how to connect the control-function with the parametric function of the graphic and then how to make an animation of the graphic so that according to the control-function the spring stretches or gets dense by moving hence and forth, very grateful for any help, I am very very new to Mathematica.

Even Help via Webex or Discord would be great,

  1. the system response and control-function

    k = 2;(Federkonstante)
    m = 5;(Masse)
    [Omega] = Sqrt[k/m];
    F = 200;(Kraft die auf Masse wirkt);

    (DGL:= x’(t)=Ax(t)+u(t)B)

    (Matrix A per Hand errechnet)
    A = {{0, [Omega]}, {-[Omega], 0}};

    (Vektor B und ihre Transponierte)
    B = {{0}, {1}};
    BT = {0, 1};

    (Matrixelemente M(t))
    f11[t_ ] := t/2 - Sin[2 Sqrt[k/m] t]/(4 Sqrt[k/m]);
    f12[t_] := (Sin[Sqrt[k/m] t])^2/(2 Sqrt[k/m]);
    f21[t_] := (Sin[Sqrt[k/m] t])^2/(2 Sqrt[k/m]);
    f22[t_] := t/2 + Sin[2 Sqrt[k/m] t]/(4 Sqrt[k/m]);
    (Matrix M(t) und ihre Inverse)
    M[t_] := {{f11[t], f12[t]}, {f21[t], f22[t]}};
    MI[t_] := Inverse[M[t]];

    (Anfangszustand)
    a0 = {{10}, {0}};

    (Zielzustand)
    z = {{0}, {0}};

    (feste Endzeit T)
    T = 20;

    (e^tA)
    e11[t_] := Cos[[Omega]*t];
    e12[t_] := Sin[[Omega]*t];
    e21[t_] := -Sin[[Omega]*t];
    e22[t_] := Cos[[Omega]*t];
    etA[t_] := {{e11[t], e12[t]}, {e21[t], e22[t]}};

    (e^tA^T)
    em11[t_] := Cos[[Omega]*t];
    em12[t_] := -Sin[[Omega]*t];
    em21[t_] := Sin[[Omega]*t];
    em22[t_] := Cos[[Omega]*t];
    etAT[t_] := {{em11[t], em12[t]}, {em21[t], em22[t]}};

    (e^-tA^T)
    etATi[t_] := Inverse[etAT[t]];

    (energieoptimale Steuerung)
    c = MI[T] . (etATi[T] . z - a0);
    u[t_] := BT . etATi[t] . c;

    (konstante Steuerung)
    (KonstanteKontrollFunktion[t_]:=(-k/m).x[t])

    (Systemantwort:)
    x[t_] := etA[t] . (a0 + M[t] . c);

NOW the following Code is/ should be the animation
Feder in German means Spring, I just noticed that my comments are in German :slight_smile:

Feder = ParametricPlot[{t + Cos[3*t], 2*Sin[3*t]}, {t, 0, 4*Pi}];
Halterung = 
  Graphics[{Black, Polygon[{{-5, -5}, {-5, 5}, {-3, 5}, {-3, -5}}]}];
LinieFederAnfang = Graphics[Line[{{-3, 0}, {1, 0}}]];
LinieFederEnde = Graphics[Line[{{4*Pi + 1, 0}, {20, 0}}]];
Masse = Graphics[{LightBlue, 
    Polygon[{{20, -2.5}, {20, 2.5}, {25, 2.5}, {25, -2.5}}]}];
MasseGezogen = 
  Graphics[{LightBlue, 
    Polygon[{{30, -2.5}, {30, 2.5}, {35, 2.5}, {35, -2.5}}]}];
Boden = Graphics[{Green, 
    Polygon[{{-3, -5}, {-3, -2.5}, {40, -2.5}, {40, -5}}]}];
Show[Halterung, LinieFederAnfang, Feder, LinieFederEnde, Masse, Boden]

Please format your code correctly and ensure that it can be copied and pasted into a notebook and evaluated. As it is, your code requires too many manual edits to fix syntax errors.

You could borrow the Manipulate code from a similar Wolfram Demonstrations Project. E.g. this one.

What is your question? I don’t know what you mean. Something like this perhaps? (There is some additional work to be done for the Feder, and make sure your other code has run)

a = 5;
Animate[{Feder = 
   ParametricPlot[{tt + Cos[3*tt], 2*Sin[3*tt]}, {tt, 0, 
     4*Pi + a Cos[t]}];
  LinieFederEnde = 
   Graphics[Line[{{(4*Pi + 1) + a Cos[t], 0}, {20 + a Cos[t], 0}}]];
  Masse = 
   Graphics[{LightBlue, 
     Polygon[{{20 + a Cos[t], -2.5}, {20 + a Cos[t], 
        2.5}, {25 + a Cos[t], 2.5}, {25 + a Cos[t], -2.5}}]}];
  Show[Halterung, LinieFederAnfang, Feder, LinieFederEnde, Masse, 
   Boden]},
 {t, 0, 10}]