数学计算经典书籍,主要矩阵论理论,曲线拟合,差值等算法#include stdio. hmain()t double t, 2static double x[101={0.10,0.15,.25,0,40,.50,0.57,0.70,0.85,0.93,1.00static double y[10]={0.904837,0.860708,0.778801,0.670320,0.606531,0.565525,0.496585,0.427415,0.394554,0.367879};t=0.632=l!rg(X,y,10,t);pintE(=%6.3f为en",t,z)运行结果为:t=0.630,z=5.32591e-011.2一元全区间等距插值功能给定n个等距结点x=x+h(=0,1,…一1)上的函数值y=f(x:),用拉格朗日( Lagrange)插值公式,计算指定插值点t处的函数近似值z=f(x)。二、方法说明同1.1节、函数语句double ablgrg( xo, h, n,y, t)四、形参说明x0——双鞘度实型变量。等距结点中的第一个结点值。h——双精度实型变量等距结点的步长。n——整型变量。等距结点的个数。y—双精度实型一维数组长度为n存放n个等距结点上的函数值。双精度实型变量指定插值点的值。五、函数程序(文件名: ablog,c)double ablgrg(xD,h,n,y,tlnt宜le xD, h,t,y ii int i,,kdouble z, 3,xi+xjzfloat p,qif (n<1) return(z),f(:==1){z=y[0]; return(z);}f(n==2{第=(y[1]〔x0)-y0*(t-x0-h))h;retu:n(z)if (toxo)ip=(t-xo)/h: i=(int)p; q=(float)ip>q)i=+1else i=0if(k<0)k=;m=1+3;if(m>n-1)m-1-1for (i=k: ifs=1.0;xi=x0+i关hfor(j=k;j=m;j十+)1 xj=xO+i*h=8#(t-x)!(x-xj);z一g…8yreturnil y六、例:设函数y=6“的网数列表如下(函数值y具有六位有效数空)50.40.9048370.8197317408180.670320.603110.545120.49551).449320.4065700.367879计算在插值忘t-0.25,0.63,0.95处的函数近似值。在利用本函数时其中x0=,1h=0.1n=10。主函数程序(文件名; ablgrgC.o)为H include 'stic. hirclude able- gMa:i double x0, hstatic double y1]={0.904837,,818731,0,740818,0.67320,0.606531,0.548812,0.496585,0,49329,0.465:0,0.57879;;0.1;h=(.1oIgrg(xU,h, 10,3, t)pr ntf( "t=9(6.3f, z=e\n",t, c)t-0. 63: z-ablgtg(xo,h,10,y,t)print("t=%6,3,z=≠em”,t,z);0.95; e-ablgrg(xo,,10,y,t)tF(+=%6.3f,z=%en",t,z)运行结果为:1=0.250,z=7.78801e—010.6302592e-00.950,z:1.3一元三点不等距插值功能给定n个不等距结点x(i=0,1,2…,n-1)二的函数值y=f(x),用抛物值公式计算指定插值虑!处时函数近似值z=f()二、方法说明设n个不等距结点为x07-x1时,取三个结点为5,+1,xk12而当xx-1=x[n-2]Ik=n-3 m=n-lRewhile (m-k|=1)i=(k+m)/2;if (t=x0+in--3)*h)ikn=ni=(int(t-x0)/h)+1;if(f会bs(t-x0一ih)>= fabs it-xQ一(-1)舞上:))k=i-2;m=i;}lse k=:1: m=i+for (i=kmi+-)1.0;X=x0+1米h十十=z-8*y[i六、例:设函数f(x)=e在10个等距结点」的函数值如下表(函数值具有六位有效数字0.20.4n.5C048373.740880.67(030Q.05530.60.80.g1.0488120.4950.4493290.406570.5678计算在值点t=0.23,063,095处的函数近似值。在利月本函数时,x0=0.1,=0.1,n=10主函数程序(文件名; adler(.c)为#include stdio. h#Include"阻double t, z,xo, hjstatic double y[i0]=10.904837,0.818731,0.740818,0.670329,0.606531,0.548812,0.496585,0.449329,0,406570,9,367879};=0.1;h=0.1t=0. 23: z=adlgrg(x0,h,10,y,t);printf("t=,5, 3f, 2=Cen",t,z)t-0.63:2- adler(x0h,10y1)printf("t=%6.3,2=%e,t,z);t=0.95;=adlgrg(xo,h,10+,t)Fprintf("t=36, 3f. z= %en",t, 2)运行结果为t=.23Uz=7.449e-1t=0.950,z=3,86715e-011.5有理不等距插值功能给定n个不等茚纳点x;(=01,…,-1)+的函数值y=f(x),用有理插值法计算指定插值点处的函数近似值。二、方法说明设给定的n个不等距结点为x0x[n-5]){k=n-8;m=8}elsek=1chile gi=(k十j/2k=k-4;m=8b[0]=y[k]for (i=2 i<=msi++)h=y[i+k-1];h=0;for (j=li j<=i-1s1++)0)(absh一b[1])+1.0==1.0)1=1+110