高分悬赏——数值逼近的c语言编程题。题目有关插值知识,数学系高材生请进。

2024-11-07 11:23:21
推荐回答(2个)
回答(1):

你要用什么插值,是牛顿插值,拉格朗日插值,Hermite插值还是三次Hermite插值

说清楚,别让我白忙活

现在才回,我吃饭了再给你写

搞定,不能像你那样说的,选那三个点作插值点,误差太大了,我选了1/5,1/4,1/2这三个点,最后的结果与用pow函数算的只差一点,误差是0.0005(主要是输入的不是很精确,如果足够精确的话,这个误差肯定还要更小.

please enter the number of the node:3
please enter the 1 point:
0.5 1.732
please enter the 2 point:
0.25 1.316
please enter the 3 point:
0.2 1.245731
please enter the test point
0.333333
3^x在0.333333处的值为1.442693:
计算机所算的结果为:1.442197
截断误差为:0.012028

程序如下:

/************************************
拉格朗日插值求3^x处的值
************************************/

#include
#include
#include

typedef struct
{
double x,y;
}point;

double Lagrange(point *node,int n,double x)
{
int i,j;
double s1,s2,s=0;
for(i=0;i {
s1=1;
s2=1;
for(j=0;j if(i!=j)
s1*=x-node[j].x;
for(j=0;j if(i!=j)
s2*=node[i].x-node[j].x;
s+=s1/s2*node[i].y;
}
return s;
}

int main()
{
int n,i;
double x;
printf("please enter the number of the node:");
scanf("%d",&n);
point *node=(point *)malloc(n*sizeof(point));
for(i=0;i {
printf("please enter the %d"" point:\n",i+1);
scanf("%lf%lf",&node[i].x,&node[i].y);
}
printf("please enter the test point\n");
scanf("%lf",&x);
printf("3^x在%lf处的值为%lf:\n",x,Lagrange(node,n,x));
printf("计算机所算的结果为:%lf\n",pow(3,0.3333));
printf("截断误差为:%f\n",0.5*1.732*0.166667*0.083333);
free(node);
return 0;
}

回答(2):

我学的就是这个专业,不过今天刚学插值法,等我一两天就可以了,嘿嘿