% rkpendel,  Runge-Kuttas metod på en pendel
  clear, clf
  global L c
  L=0.8;  c=0.1; 
  subplot(2,3,1), plot([0 L],[0 0], L,0,'o')
  axis([-1 1 -1 1]), axis square, hold on
  title('Pendeln')
  tslut=5;   dt=0.1  
  t=0;  y=[pi/2 0];  Y=y;  T=t;
  while t<tslut-dt/2         
    f1=fpend(y);  
    f2=fpend(y+dt*f1/2);
    f3=fpend(y+dt*f2/2);
    f4=fpend(y+dt*f3);
    y=y+dt*(f1+2*f2+2*f3+f4)/6;  t=t+dt; 
    Y=[Y; y];   T=[T; t];
    xL=L*sin(y(1));  yL=-L*cos(y(1));
    plotus([0 xL],[0 yL],'-'), plotus(xL,yL,'o'), drawnow
  end, t, y
  fi=Y(:,1);  fiprim=Y(:,2);
  subplot(2,3,2), plot(T,fi, T,fiprim,':')
  subplot(2,3,3), plot(fi,fiprim)
  xlabel('Vinkeln fi'); ylabel('fiprim')




