clear all
clc
close all

N = 100000;
deltat = 0.0001;

x1 = zeros(N, 1);
x2 = zeros(N, 1);

x1(1) = 10;
x2(1) = 0;

n = 1;
while n <= N - 1
  m1   = x2(n)
  provx1 = x1(n) + m1 * deltat;
  k1 = -0.1 * x2(n) - 5 * x1(n);
  provx2 = x2(n) + k1 * deltat;
  m2 = provx2;
  k2 = -0.1 * provx2 - 5 * provx1
  m  = (m1 + m2) / 2;
  k  = (k1 + k2) / 2;

  x1(n+1) = x1(n) + m * deltat;
  x2(n+2) = x2(n) + k * deltat;

  n += 1;
end



figure(1, "visible", "off");
plot(x1);
grid;
print -deps "../media/runge-kutta2.eps";
