% Differenzialgleichungen:

phip   = inline ('omega','omega') ;
omegap = inline ('-faktor*sin(phi)','t','phi','omega','faktor') ;

pl     = 1 ;                               % Pendellaenge
g      = 9.81 ;                            % Erdbeschleunigung
faktor = 1.5*g/pl ;

t0 = 0 ;  phi0 = pi/2 ; omega0 = 0 ;       % Anfangswerte
tEnd = 10  ;                               % Ende des Integrationsintervalls
n    = 200 ;                               % Anzahl der Integrationsschritte
dt   = (tEnd - t0) / n ;

t = t0 : dt : tEnd    ;
phi   = zeros (n+1,1) ;
omega = zeros (n+1,1) ;

% Runge-Kutta-Algorithmus -------------------------------------------------- 
phi(1)   = phi0   ;
omega(1) = omega0 ;

for i=1:n
    k1phi = phip   (omega(i)) ;
    k1om  = omegap (t(i),phi(i),omega(i),faktor) ;
    k2phi = phip   (omega(i)+k1om*dt/2) ;
    k2om  = omegap (t(i)+dt/2,phi(i)+k1phi*dt/2,omega(i)+k1om*dt/2,faktor) ;
    k3phi = phip   (omega(i)+k2om*dt/2) ;
    k3om  = omegap (t(i)+dt/2,phi(i)+k2phi*dt/2,omega(i)+k2om*dt/2,faktor) ;
    k4phi = phip   (omega(i)+k3om*dt) ;
    k4om  = omegap (t(i+1),phi(i)+k3phi*dt,omega(i)+k3om*dt,faktor) ;
    phi  (i+1) = phi  (i) + (k1phi + 2*k2phi + 2*k3phi + k4phi) * dt/6 ;
    omega(i+1) = omega(i) + (k1om  + 2*k2om  + 2*k3om  + k4om)  * dt/6  ;
end
% Runge-Kutta-Algorithmus --------------------------------------------------

phiMin=min(phi) , omegaMax=max(abs(omega)) % Extremwerte ---> Command Window
plot (t,phi)                               % Graphik-Ausgabe phi(t)

