❶ 牛頓的插值法用C語言怎麼編寫怎麼編啊
程序代碼如下。
希望能幫助到你!
牛頓插值法
#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=1;k<=n;k
)
{
f[0]=y[k];
for(i=0;i<k;i
)
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
*
❷ 求用c語言編寫牛頓插值法
牛頓插值法:
#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=0;i<=n-1;i++)
{
a[i]=y[i];
for(j=0;j<=n-1;j++)
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=1;k<=n;k++)
{
f[0]=y[k];
for(i=0;i<k;i++)
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-1;i>=0;i--)b=b*(varx-x[i])+y[i];
printf("Nn(%f)=%f",varx,b);
getchar();
}
留下個郵箱,我發給你:牛頓插值法的程序設計與應用