学期:至第学期年月日课程名称:___计算机数值方法___专业:级班实验编号:2实验项目分段线性、分段二次插值多项式指导教师__张莉_姓名:学号:实验成绩:一、实验目的及要求实验目的:,提高插值精度的思想和这种用低代价换取高回报的手段。、分段二次插值多项式公式;。实验要求:、二次插值算法;。二、实验内容用下列插值节点数据,构造分段线性插值多项式,并计算f(),f()的值。(x)、实验步骤()步骤一:写出分段插值函数的算法:输入n的值,及节点值(xi,yi),i=0,1,2,3……n;记f(xi)=yiFori=0,1,2,….n-1在[xi,xi+1]上计算Pi(x)=f(xi)*(x-xi+1)/(xi-xi+1)+f(xi+1)(x-xi)/(xi+1-xi)[x_k,x_k+1,x_k+2]上计算P(x)=∑y_i*(∏(x-x_r)/(x_j-x_r)),计算结果。步骤二:输入分段插值函数的程序如下:#include<>#defineMAX_N20typedefstructtagPOINT/*thestructerofpoint*/{doublex;doubley;}POINT;intmain(){intn,i,j,k,l,r;POINTpoints[MAX_N+1];doublex;doublelar1;doubletmp=;doublelar2=;clrscr();printf("\nInputnvalue:");/*thenumberofthepointsinserted*/scanf("%d",&n);if(n>MAX_N){printf("TheinputnislargerthanMAX_N,heMAX_N.\n");return1;}if(n<=0){printf("Pleaseinputanumberbetween1and%d.\n",MAX_N);}printf("Nowinputthe(x_i,y_i),i=0,...%d:\n",n);for(i=0;i<=n;i++)scanf("%lf%lf",&points[i].x,&points[i].y);printf("Nowinputthexvalue:");/*thevalueofx*/scanf("%lf",&x);printf("theresultoffenduanchazhiyicihanshuis::\n");//一次插值拉格朗日函数的实现for(i=0;i<n;i++){if(x>=points[i].x&&x<=points[i+1].x){ lar1=(x-points[i+1].x)/(points[i].x-points[i+1].x)*points[i].y+(x-points[i].x)/(points[i+1].x-points[i].x)*points[i+1].y; break;}}printf("oncetime'sresultis::%f
数值分析 实验二分段插值 来自淘豆网m.daumloan.com转载请标明出处.