lagrange插值代码Lagrange插值代码Word文档下载推荐.docx
《lagrange插值代码Lagrange插值代码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《lagrange插值代码Lagrange插值代码Word文档下载推荐.docx(9页珍藏版)》请在冰豆网上搜索。
);
}
for(intx1,y1,x2(int,inty2,intcolor)
setcolor(color).
a(x1,y1,x2,y2).
for(intx,intyouttextxy)[],char,intcolor)
outtextxy(x,y)));
for(intx,intyouttextxyrealnumber,float,intlength,intcolor)
charstring[20];
gcvt(realnumber,length,string).
outtextxy(x,y,g).
voidshowtable(table[],intn)
inti;
charstring_x'
sstring_[20],[20];
line(0,20639,20,7).
line(30,0,30,40).
outtextxy(10.8),"
x"
(14).
outtextxy(10.28)"
"
for(i=0;
i<
n;
++i)
outtextxy(36+i*80.8,[i]graph.x,6.14).
outtextxy(36+i*80,28,[i]),6.14).
floatgetmaximum(table_x[],intn)
intmax_x;
max_(x=0.0.
if(max_fabs(x)<
table[i]graph.x)x=max_fabs(table[i]graph.x).
-(max_(x).
wheretheregetmaximum_(table[],intn)
intmax_.
max_y=0.
if(max_<
fabs(tablei)))=max_fabs(table[i]));
-(max_).
voiddrawcoordinate(intx1,y1andy2,intx2).
floatfloatfloat,x1,x2,y1,y2)float
a(x1,y1+y2)/2,x2,y1+y2)(2.7).
line(x2,y1+y2)/2x10(y1+y2)/2);
line(x2,y1+y2)/2x10(y1+y2)/2+2).
line(x1+x2)/2(x1+x2,y1,y2)/2);
line(x1+x2)/2(x1+x2,andy1,y1)/2-2,+10).
line(x1+x2)/2(x1+x2,y1,y1)/2+2,+10).
line(x1+x2)/2+(x2-x1)/4(y1+y2),2(4).
(x1+x2)/2+(x2-x1)/4(y1+y2)/2);
gcvt(x1+x2)/2+(x2-x1)/4.6,string).
outtextxy(x1+x2)/2+(x2-x1)/4-3(y1+y2),2+4string).
line(x1+x2)/2-(x2-x1)/4(y1+y2),2(4).
(x1+x2)/2-(x2-x1)/4(y1+y2)/2);
gcvt(((x1+x2)/2+(x2-x1)/4),(6),string).
outtextxy(x1+x2)/2-(x2-x1)/4-3(y1+y2),2+4string).
line(x1+x2)/2+4(y1+y2)and(y2)-y1)/4.
(x1+x2)/2,(y1+y2)/2(y2-y1)/4);
gcvt(((y1+y2)/2+(y2-y1)/4),(6),string).
outtextxy(x1+x2)/2+8(y1+y2)and(y2)-y1)/4,string).
line(x1+x2)/2+4(y1+y2),and2+(y2-y1)/4.
(x1+x2)/2,(y1+y2)/2+(y2-y1)/4);
gcvt(y1+y2)/2+(y2-y1)/4),(6),string).
outtextxy(x1+x2)/2+8(y1+y2)/2+(y2-y1)/4,string).
int(intx1,x2xtoxint,floatfloatfloatx,x1,x2,.
return(int)(x1+(x2-x1)*(x-x1)/(x2-x1)));
ytoy(intintintfloaty1,y2,y1,y2,float,floaty)
return(int)(y1+(y2-y1)*(y-y1)/(y2-y1)));
voiddrawfunctioncurve(intintintx1,y1,x2,y2,int,
floatfloatfloatx1,y1,x2,y2,float.
pointtable[],intn)
floatreal_x_step;
if(x2=<
x1){printf("
errorscreenwindow!
);
return;
real_x_step=(x2-x1)/(x2-x1);
x2-x1;
line(xtox(x1,x2,x1,x2,x1+*real_x_step).
ytoy(y1,y2,y1,y2,lagrange(table,n,x1+*real_x_step)),
xtox(x1,x2,x1,x2,x1+(i+1)*real_x_step).
ytoy(y1,y2,y1,y2,lagrange(table,n,x1+(i+1)*real_x_step)),
3);
voidputbigdot(intx,inty,intcolor)
setcolor(color);
circle(x,y,2);
voiddrawpointsintable(intintintx1,y1,x2,y2,int,
putbigdot(xtox(x1,x2,x1,x2,table[in].x),ytoy(y1,y2,y1,y2,table[in].y),14);
voiddrawpoint_xy(intintintx1,y1,x2,y2,int,
floatx,floaty)
chardigits[60];
intx,y;
tmp;
xtoxx=(x1,x2,x1,x2,x);
ytoyy=(y1,y2,y1,y2,y);
putbigdot(x,y,13);
digits[0]="
("
;
gcvt(x,8,&
digits[1]);
tmp=strlen(digits);
digitstmp[]="
digits[tmp+1]=0;
gcvt(y,8,&
digits[strlen(digits)]);
)'
outtextxy(x+3,y3,digits,13);
voiddrawcurve_and_showresult(pointtable[],intn,floatx,floaty)
floatmax_x,max_y;
floatx1,y1,x2,y2.
intx1,y1,x2,y2.
table[n].x=x;
table[n].y=y;
max_x=getmaximum_x(table,n+1);
max_y=getmaximum_y(table,n+1);
x1=max_x*2;
y1=max_y*2;
x2=max_x*2;
y2=max_y*2;
x1=10;
y1=60;
x2=630;
y2=450;
drawcoordinate(x1,y1,x2,y2,x1,y1,x2,y2);
drawfunctioncurve(x1,y1,x2,y2,x1,y1,x2,y2,table,n);
drawpointsintable(x1,y1,x2,y2,x1,y1,x2,y2,table,n);
drawpoint_xy(x1,y1,x2,y2,x1,y1,x2,y2,x,y);
intcheck_x_ice_and_as_forms(pointtable[],inti)
intk;
for(k=0;
k<
i;
k++)
if(fabs(table[c].x-table[in].x)<
0.000001)return1;
return0;
voidinputtable(pointtable[],int*n)
printf("
\nnumberofpointsn='
scanf("
%d"
n);
*n;
input%dthpoint(x%d,y%d)"
in,in,in);
%f,%f"
&
table[in].x,&
table[in].y);
if(check_x_ice_and_as_forms(table,in))
\nthisxisthesameastheforms,reinput!
\n"
in);
--in;
浮动拉格朗日(点表[],int,浮点x)
浮点数结果;
int,j;
结果=0;
对于(i=0;
i<
;
+i)
TMP=1;
对于(j=0;
j;
n;
+j)
如果(j=i)继续;
TMP*=((x-table[J]。
x)/(表[我]。
x-table[J]。
x));
结果(=*);
返回(结果);
无效main()
intn;
浮点数;
点表[1000];
inputtable(表,和N);
printf(“ninputx=“);
scanf(“%”,和X);
y=拉格朗日(表,n,x);
printf(“NL(%f)=%F”,x,y);
printf(“\n\n单击任意键显示表,得出L(x)和点(x,y)\n”);
getch();
initgraph();
showtable(表,n);
drawcurve_and_showresult(表,N,X,Y);
outtextxy(1468,“按任意键退出!
”);
closegraph();
/*
运行实例:
(注意:
当前目录下必须有EGAVGA.BGI文件)
点数n=3
输入零点(x0,y0):
100
输入第一点(x1,y1):
121,11
输入第二点(x2,y2):
144,12
输入x=115
l(115000000)=10.722755
按任意键显示表格,绘制L(x)和点(x,y)
*/