% [x,y] = runge_kutta_2(y_0,x_0,x_final,dx)
function [x,y] = runge_kutta_2(y_0,x_0,x_final,dx)

% for dy/dx = f(y(x),x)
%
% first define f1 = dx f(y(x),x)
%
% xhen 
%
% y(x+dx) ~ y(x) + dx/2 f(y(x),x) + dx f(y(x)+f1,x+dx)
%
% number of steps to take 
n = ceil((x_final-x_0)/dx) + 1;

% pux initial data into vector
x(1) = x_0;
y(1) = y_0;
for i=1:n-1
  f1 = dx*F(y(i),x(i));
  y(i+1) = y(i) +  f1/2 + dx*F(y(i)+f1,x(i)+dx)/2;
  x(i+1) = x_0 + i*dx;
end
