function ex20()
m1 = 5; m2 = 0.5;
c1 = 10; c2 = 1;
b1 = 0.1; b2 = 0.1;
F1 = 1;
Om = 1.414;

M = [m1, 0; 0, m2];
C = [c1+c2,-c2;-c2,c2];
B = [b1+b2,-b2;-b2,b2];
Fhat = [F1; 0];

% Bewegung ohne Tilger
[t, y] = ode45(@(t,y) f1d(t,y,m1,b1,c1, F1, Om), [0 60], [0 0]);
x = y(:,1);

plot(t, x);
xlabel("t [s]","FontSize",12);
ylabel("x [m]","FontSize",12);
F = getframe(gcf);
imwrite(F.cdata, "bild68.png");

% nochmal für längere Zeit
[t, y] = ode45(@(t,y) f1d(t,y,m1,b1,c1, F1, Om), [0 600], [0 0]);
x = y(:,1);

plot(t, x);
xlabel("t [s]","FontSize",12);
ylabel("x [m]","FontSize",12);
F = getframe(gcf);
imwrite(F.cdata, "bild69.png");

% Amplitude herauslesen
index = find(t >= 500);
xSpaet = x(index);
amplitude1d = max(abs(xSpaet))

% Bewegung mit Tilger
[t, y] = ode45(@(t,y) f2d(t,y,M,B,C, Fhat, Om), [0 200], [0 0 0 0]);
x1 = y(:,1);
x2 = y(:,2);

plot(t, x1, t, x2);
xlabel("t [s]","FontSize",12);
ylabel("x [m]","FontSize",12);
legend("Schwinger", "Tilger")

F = getframe(gcf);
imwrite(F.cdata, "bild70.png");

% Amplituden herauslesen
index = find(t >= 100);
xSpaet = x1(index);
amplitude2d = max(abs(xSpaet))
amplitudeTilger = max(abs(x2(index)))
maxTilger = max(abs(x2))


%---------------------------------------------------------------
function dydt = f1d(t, y, m, b, c, F, Om)
% rechte Seite der DGL bei erzwungener Schwingung ohne Tilger
x = y(1);
v = y(2);
dydt = [v; (F*cos(Om*t) - b*v - c*x)/m];


function dydt = f2d(t, y, M, B, C, Fhat, Om)
% rechte Seite der DGL bei erzwungener Schwingung mit Tilger
x = y(1:2);
v = y(3:4);

dx = v;
dv = inv(M)*(Fhat*cos(Om*t) - B*v - C*x);
dydt = [dx; dv];
