牛顿插值法
#include<stdio.h>
#include<math.h>
#define
n
4
void
difference(float
*x,float
*y,int
n)
{
float
*f
int
k,i
f=(float
*)malloc(n*sizeof(float))
for(k=1k<=nk
)
{
f[0]=y[k]
for(i=0i<ki
)
f[i
1]=(f[i]-y[i])/(x[k]-x[i])
y[k]=f[k]
}
return
}
main()
{
int
i
float
varx=0.895,b
float
x[n
1]={0.4,0.55,0.65,0.8,0.9}
float
y[n
1]={0.41075,0.57815,0.69675,0.88811,1.02652}
difference(x,(float
*
牛顿插值法:#include<stdio.h>
#include<alloc.h>
float Language(float *x,float *y,float xx,int n)
{
int i,j
float *a,yy=0.0
a=(float *)malloc(n*sizeof(float))
for(i=0i<=n-1i++)
{
a[i]=y[i]
for(j=0j<=n-1j++)
if(j!=i)a[i]*=(xx-x[j])/(x[i]-x[j])
yy+=a[i]
}
free(a)
return yy
}
void main()
{
float x[4]={0.56160,0.5628,0.56401,0.56521}
float y[4]={0.82741,0.82659,0.82577,0.82495}
float xx=0.5635,yy
float Language(float *,float *,float,int)
yy=Language(x,y,xx,4)
printf("x=%f,y=%f\n",xx,yy)
getchar()
}
2.牛顿插值法#include<stdio.h>
#include<math.h>
#define N 4
void Difference(float *x,float *y,int n)
{
float *f
int k,i
f=(float *)malloc(n*sizeof(float))
for(k=1k<=nk++)
{
f[0]=y[k]
for(i=0i<ki++)
f[i+1]=(f[i]-y[i])/(x[k]-x[i])
y[k]=f[k]
}
return
}
main()
{
int i
float varx=0.895,b
float x[N+1]={0.4,0.55,0.65,0.8,0.9}
float y[N+1]={0.41075,0.57815,0.69675,0.88811,1.02652}
Difference(x,(float *)y,N)
b=y[N]
for(i=N-1i>=0i--)b=b*(varx-x[i])+y[i]
printf("Nn(%f)=%f",varx,b)
getchar()
}
留下个邮箱,我发给你:牛顿插值法的程序设计与应用
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)