clear all;
format long;
h = 0.25;
b = 1;
a = 0;
n = (b-a)/h;
tol = 10^(-6);
v(1,1) = -1;
v(1,2) = -1;
v(1,3) = -1;
for j=2:(n+1)
    t = (j-1)*h;
    v(j,1) = t - exp(-5*t); % Exact solution
    
    t = (j-2)*h;
    w = v(j-1,2);
    k1 = h*fun(t,w);
    k2 = h*fun(t +(h/2), w+(k1/2));
    k3 = h*fun(t +(h/2), w+(k2/2));
    k4 = h*fun(t+h , w+k3);
    v(j,2) = w + (1/6)*(k1 + 2*k2 + 2*k3 + k4); %Runge-Kutta Order 4
    
    clear y;
    firstiter = 0;
    w = v(j-1,3);
    k = 2;
    y(1) = w + (h/2)*fun(t,w); %Initial guess determined by Euler's method
    y(2) = y(1) + 1;
    while (abs(y(k) - y(k-1)) > tol)
        if (firstiter == 1)
            k = k + 1;
        end
        num = y(k-1) - w - (h/2)*(fun(t,w) + fun(t + h, y(k-1)));
        den = 1 - (h/2)*fy(t + h, y(k-1));
        y(k) = y(k-1) - (num/den);
        firstiter = 1;
    end
    v(j,3) = y(k); %Implicit Trapezoidal Method
end