function [] = rk4()
%RK4 Runge-Kutta-Verfahren 4. Ordnung fuer y'(t) = y(t), y(0) = 1

close all
help rk4

dt = input(' dt [0.2]: ');
if isempty(dt)
   dt = 0.2;
end

tmax = 2.0;

figure(1)
axis([0 tmax 0 exp(tmax)])
hold on

% Anfangsbedingung ---------------------------------
t = 0.0;
y = 1.0;
% Runge-Kutta-Schritte -----------------------------
while t <= tmax
      plot(t,y,'+r','Markersize',10,'Linewidth',1.6)
      k1 = f(t,y);
      k2 = f(t+0.5*dt,y+0.5*dt*k1);
      k3 = f(t+0.5*dt,y+0.5*dt*k2);
      k4 = f(t+1.0*dt,y+1.0*dt*k3);
      y = y + (dt/6.0)*(k1 + 2.0*(k2 + k3) + k4);
      t = t + dt;
end
% --------------------------------------------------

t = linspace(0, tmax);
plot(t,exp(t),'-b')
hold off
title(['Runge-Kutta-Verfahren: y''(t)=y(t), y(0)=1, \Deltat = ' num2str(dt)],...
       'FontSize',18)
xlabel('t', 'FontSize', 18)
ylabel('y(t)', 'FontSize', 18)
set(gca, 'FontSize', 18)
box on
print -depsc rk4.eps


%----------------------
function dydt = f(~, y)
dydt = y;
%----------------------