bild28.m

function bild28()
% Erzeugung von Bild 28 und 29

% Matrixwerte
M = eye(4);
C = [1,0,0,0; 0,2,0,-1; 0,0,1,0; 0,-1,0,2];

% Anfangsbedingungen
x0 = [0.2; 0; -0.1; 0.2];
v0 = zeros(4, 1);

% DGL lösen
tEnd = 20;
myfunc = @(t, y) schwingNd(t, y, M, C);
[t, y] = ode45(myfunc, [0, tEnd], [x0; v0]);
 
% Ergebnisse plotten
subplot(2,1,1)
plot(t, y(:,1), t, y(:,2));
title("Masse 1", "FontSize", 14)
legend("x", "y", "Location", "best");
subplot(2,1,2)
plot(t, y(:,3), t, y(:,4));
title("Masse 2", "FontSize", 14)
legend("x", "y", "Location", "best");

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

% Bahnkurven plotten
subplot(2,1,1)
plot(y(:,1), y(:,2));
title("Masse 1", "FontSize", 14)
subplot(2,1,2)
plot(y(:,3), y(:,4));
title("Masse 2", "FontSize", 14)
axis([-0.2, 0.2, -0.2, 0.2])

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