// Adams-Bashforth 4-step Explicit Method
#include <stdio.h>
#include <math.h>
#define F(t,y) (-((y)+1.0)*((y)+3.0))
#define ExactF(t) (-3.0+2.0/(1.0+exp(-2*(t))))
#define t0 0.0
#define te 2.0
#define num 20.0
void main()
{
double w[100], t;
double h=(te-t0)/num;
int i;
t=t0+h*3.0;
w[0]= -2.0; // Runge-Kutta order 4·Î ±¸ÇÑ °ªµé
w[1]= -1.90033209;
w[2]= -1.80262486;
w[3]= -1.70868768;
for(i=3; i<num; i++) {
w[i+1]=w[i]+h/24.0*(55.0*F(t,w[i]) - 59.0*F(t-h,w[i-1])
+ 37.0*F(t-2.0*h,w[i-2]) - 9.0*F(t-3.0*h,w[i-3]));
t+=h;
}
printf(" ti Exact wi Error\n");
for(i=0; i<=num; i++)
printf("%4.2f %12.8f %12.8f %12.8e\n",
t0+h*i, ExactF(t0+h*i), w[i], fabs(ExactF(t0+h*i)-w[i]));
}