// Euler预测-校正法.cpp : 定义控制台应用程序的入口点。
//
/*
解 y'=x+y 0<=x<=1
y(0) = 1
取h=0.1
准确解:y(x)=-x-1+2*exp(x)
*/
#include"stdafx.h"
#include"math.h"
#include"iostream"
using namespace std;
inline double fun1(double x,double y)
{
return x+y;
}
inline double fun2(double x)
{
return -x-1+2*exp(x);
}
void main(void)
{
const double a=0,b=1,n=10,y0=1,h=(a+b)/n;
int i;
double x,y;
double yp,yc;
x=a,y=y0;
cout<<'x'<<"\t\t"<<'y'<<"\t\t"<<"准确值"<<"\t\t"<<"差值"< for(i=1;i<=n;i++) { yp=y+h*fun1(x,y); yc=y+h*fun1(x+h,yp); y=0.5*(yp+yc); x=a+i*h; cout< } }