% A 4-step Adams-Bashforth method
clear all

h = 0.025;
N = 40;

f = @(t,x) -2*t*x^2;

exact = @(t) 1/(1+t^2);

t(1) = 0;
x(1) = 1;
y(1) = exact(t(1));
f1 = f(t(1),x(1));

t(2) = h;
x(2) = exact(t(2));
y(2) = exact(t(2));
f2 = f(t(2),x(2));

t(3) = 2*h;
x(3) = exact(t(3));
y(3) = exact(t(3));
f3 = f(t(3),x(3));

t(4) = 3*h;
x(4) = exact(t(4));
y(4) = exact(t(4));
f4 = f(t(4),x(4));

for i=4:N
    
    x(i+1) = x(i) + (h/24)*( 55*f4 - 59*f3 + 37*f2 - 9*f1 );
    t(i+1) = t(i) + h;
    y(i+1) = exact(t(i+1));
    f1 = f2;
    f2 = f3;
    f3 = f4;
    f4 = f(t(i+1),x(i+1));
    
end
