数值分析实验二分段插值.docVIP

  • 58
  • 0
  • 约2.54千字
  • 约 4页
  • 2017-06-07 发布于重庆
  • 举报
数值分析实验二分段插值

数学与软件科学学院 实验报告 学期: 至 第 学期 年 月 日 课程名称:___计算机数值方法___ 专业: 级 班 实验编号:2 实验项目 分段线性、分段二次插值多项式 指导教师__张莉_ 姓名: 学号: 实验成绩: 一、实验目的及要求 实验目的: 1. 体会分段低次插值在不增加结点的情况下,提高插值精度的思想和这种用低代价换取高回报的手段。 2. 熟练掌握分段一次、分段二次插值多项式公式; 3. 掌握分段插值多项式算法设计的特点。 实验要求: 1. 给出分段一次、二次插值算法; 2. 用C语言实现算法 3. 给出误差分析。 二、实验内容 用下列插值节点数据,构造分段线性插值多项式,并计算f 1.075 ,f 1.175 的值。 x 1.05 1.10 1.15 1.20 F x 2.12 2.20 2.17 2.32 三、实验步骤 该部分不够填写.请填写附页 步骤一:写出分段插值函数的算法: 输入n的值,及节点值(xi,yi),i 0,1,2,3……n;记f xi yi For i 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 3. 在[x_k,x_k+1,x_k+2] 上 计算 P x ∑y_i* ∏ x-x_r / x_j-x_r 4.输入x的值,计算结果。 步骤二:输入分段插值函数的程序如下: #include #define MAX_N 20 typedef struct tagPOINT /*the structer of point */ double x; double y; POINT; int main int n,i,j,k,l,r; POINT points[MAX_N+1]; double x; double lar1; double tmp 1.0; double lar2 0.0; clrscr ; printf \nInput n value : ; /*the number of the points inserted*/ scanf %d,n ; if n MAX_N printf The input n is larger than MAX_N,please redefine the MAX_N.\n ; return 1; if n 0 printf Please input a number between 1 and %d.\n,MAX_N ; printf Now input the 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 Now input the x value: ; /*the value of x*/ scanf %lf,x ; printf the result of fen duan cha zhi yi ci han shu is::\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 once times result is::%f\n,lar1 ; printf the results of fen duan cha zhi er ci han shu is::\n ; //二次插值拉格朗日函数的实现 i 0; while i n-1 if x points[1].x k 0;break; else if x points[n-2].x k n-2;break; else if x points[i].x x points[i+1].x fabs x-points[i].x fabs x-points[i+1].x k i-1;break; else if x points[i].x x points[i+1].x fabs x-points[i].x fabs x-points[i+1].x k i;break; else i++; for j k;j k+2;j++ for r k;r k+2 r! j;r++ tmp* x-poin

文档评论(0)

1亿VIP精品文档

相关文档