西安翻译学院就业中心:李查逊外推加速法

来源:百度文库 编辑:神马品牌网 时间:2024/05/07 17:09:21

这是用C语言写的李查逊外推加速法求积分
#include <conio.h>
#include <stdio.h>
#define N 10
float a[8]={3.147374,5.703909,6.151006,8.657186,
0.001831,3.163549,5.738090,5.894040};
float f(float x)
{ float y;
int i;
y=a[0];
for(i=1;i<8;i++)
y=y*x+a[i];
return y;
}
float fx(float a,float b)
{
int i,j=1,m,n;
float h,s,t[N][N],k;
t[0][0]=(f(a)+f(b))/2;
for(m=1;m<N;m++)
{
s=0;k=4.0;
h=(b-a)/j;
for(i=0;i<j;i++)
s+=f(a+(i+1.0/2)*h);
t[m][0]=t[m-1][0]/2+h/2*s;
j*=2;
for(n=1;n<=m;n++)
{
t[m][n]=(k*t[m][n-1]-t[m-1][n-1])/(k-1);
k*=4;
}
}
return t[N-1][N-1];
}
void main(void)
{
float a,b;
a=0.46147;b=4.163671;
clrscr();
printf("The result is:%f\n",fx(a,b));
getch();
}