% Function for Classical Runge-Kutta Method on an equation of the type:
% y'=fun(x,y)
%
% the user must input fun, initial value for y,
% a 2-component vector for xspan, and the desired step size.


function [x,Y] = cRK_1eq(fun,yint,xspan,h);

Y(1) = yint;
x = xspan(1) :h: xspan(2);

for n = 1 : length(x)-1
    k1 = h* feval(fun,  x(n),  Y(n));
    k2 = h* feval(fun,  x(n)+1/2*h,  Y(n)+1/2*k1);
    k3 = h* feval(fun,  x(n)+1/2*h,  Y(n)+1/2*k2);
    k4 = h* feval(fun,  x(n)+h,  Y(n)+k3);
    
    Y(n+1) = Y(n) + 1/6* ( k1 + 2*k2 + 2*k3 + k4 );
    
end