资源描述:
《C三次样条插值函数(自然边界).docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/****************函数说明*********************///pxpy为已知的数据点,xs为要插值的x坐标,最终会得到xs坐标下的y值usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacespline{classProgram{staticvoidMain(string[]args){point[]points=newpoint[13];double[
2、]px={64,304,544,1035,1502,2061,2540,2939,3498,3897,4456,4696,4936};double[]py={4.663,4.476,4.969,4.853,4.766,5.2415,4.795,4.7055,5.4565,5.5515,5.411,5.8385,6.7085};for(inti=0;i<13;i++){points[i]=newpoint();points[i].x=px[i];points[i].y=py[i];}point.De
3、SortX(points);double[]xs={64,304,544,1023,1502,1981,2460,2939,3418,3897,4376,4616,4856};splineInsertPoint(points,xs,1);Console.ReadLine();}staticdouble[]splineInsertPoint(point[]points,double[]xs,intchf){intplength=points.Length;double[]h=newdouble[pl
4、ength];double[]f=newdouble[plength];double[]l=newdouble[plength];double[]v=newdouble[plength];double[]g=newdouble[plength];//三转角法的待定一阶系数法。基本方程为l(i)m(i-1)+2m(i)+u(i)m(i+1)=g(i),i=1,2,...,n-1//目前有n-1个方程,n+1个未知量(从m0到mn),需要添加两个边界条件for(inti=0;i5、++)//共有plength(n+1)个点,h总有plength-1(n)个值{h[i]=points[i+1].x-points[i].x;}for(inti=1;i6、ngth=n+1阶矩阵double[]L=newdouble[plength];//下三角矩阵Ldouble[]m=newdouble[plength];//用于保存m0-mn的一阶系数数值double[]Y=newdouble[plength];//中间矩阵Y/***********************矩阵分界,求解待定的一阶系数,m1到m(n-1)*************************/U[0]=2;v[0]=1;for(inti=1;i7、[i]/U[i-1];U[i]=2-v[i-1]*L[i];}Y[0]=g[0];for(inti=1;i=0;i--){m[i]=(Y[i]-v[i]*m[i+1])/U[i];}/**************************************************************
8、***************************/intxlength=xs.Length;//记录需要插值的点的个数double[]insertRes=newdouble[xlength];//用于返回插值点的Y坐标for(inti=0;i