Milne Predictor Corrector
#include<stdio.h>
#include<math.h>
float
x[5],y[5],h;
float
f(int i)
{ return
x[i]-y[i]*y[i];
}
void correct()
{ y[4] =y[2]+(h/3)*(f(2)+4*f(3)+f(4));
printf("%23s
%8.4f %8.4f\n"," ",y[4],f(4));
}
main()
{ float xr,aerr,yc;
int i;
puts("enter the value of x0,xr,h,"
"allowed error"); scanf("%f,%f,%f,%f",&x[0],&xr,&h,&aerr);
puts("enter the value of y[i], i=0.3");
for(i=0;i<=3;i++)
scanf("%f",&y[i]);
for(i=1;i<=3;i++)
x[i]=x[0]+i*h;
puts(" x predicted" "corrected");
puts(" y f" "y f");
while(1)
{ if(x[3]= xr) return;
x[4]=x[3]+h;
y[4]=y[0]+(4*h/3)*(2*(f(1)+f(3))-f(2));
printf("%6.2f
%8.4f %8.4f\n",x[4],y[4],f(4));
correct();
while(1)
{
yc
=y[4]; correct();
if(fabs(yc-y[4]) <=aerr)
break;
}
for(i=0;i<=3;i++)
{
x[i]=x[i+1];
y[i]=y[i+1];
}}}
Output