function T12_Beispiel_Federpendel
close all

% Parameter
global g l_F m c
m   = 10;
c   = 1000;
g   = 9.81;
l_F = 1;

t_end = 5.; 
phi0 = pi/4; phi0_p = 0;
l0=l_F; l0_p=0;

% Lösen der DGL
[t,z]=ode45(@dgl,[0 t_end],[phi0 l0 phi0_p l0_p],[]); 

% Plot 
subplot(2,2,1)
plot(t,z(:,1),'-'); grid on
title(['Winkel'])

subplot(2,2,2)
plot(t,z(:,3),'-'); grid on
title(['Winkelgeschwindigkeit'])

subplot(2,2,3)
plot(t,z(:,2),'-'); grid on
title(['Länge'])

subplot(2,2,4)
plot(t,z(:,4),'-'); grid on
title(['Länge: Geschwindigkeit'])

end

function z_p=dgl(t,z)
   global g l_F m c
   z_p=[z(3);...
        z(4);...
        -1/z(2)*(g*sin(z(1))+2*z(4)*z(3));...
        -c/m*(z(2)-l_F)+g*cos(z(1))+z(2)*z(3)^2];
end


