#include<stdio.h>
float lagrange(int n,float x[],float y[],float xx)
{
float temp,yy;
int i,j;
yy=0;
for(i=0;i<n;++i)
{
temp=y[i];
for(j=0;j<n;++j)
if(j!=i)
temp=temp*(xx-x[j])/(x[i]-x[j]);
yy=yy+temp;
}
return yy;
}
int main()
{
int n;
float x[10],y[10],xx,yy;
yy=0;
printf("Please input nodes n; Interpolation node coordinates x[],\n");
printf("a point interpolation function value y[], to be calculated point coordinates xx\n");
scanf("%d",&n);
for(int i=0;i<n;++i)
scanf("%f",&x[i]);
for(int j=0;j<n;++j)
scanf("%f",&y[j]);
scanf("%f",&xx);
yy=lagrange(n,x,y,xx);
printf("yy:%f\n",yy);
return 0;
}
lagrange
最新推荐文章于 2023-08-14 00:55:23 发布