资源描述:
《样条函数拟合》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、样条函数拟合方法样条函数拟合是将复杂曲线分为多段,段内用3次多项式进行拟合,同时保证分段的左右短连续且一、二次可导,以保证连接处的光滑。PublicFunctionFitBySpline(ByValX()AsSingle,ByVaiY()AsSingle,ByVaiSectorlndexs()AsInteger)AsArray,按照X点生成拟合后Y坐标'Sectorindex段索引,Sectorlndexs段端所指的点索引DimYl(UBound(X))AsSingle,iAsInteger,Sectorind
2、exAsInteger,XLKAsSingle,ConfAsArrayConf=FitBySpline(X,Y,Sectorlndexs),拟合出曲线系数Fori=0ToUBound(X)Sectorindex=SearchSectorIndex(SearchIndex(X(i),X),Sectorlndexs)XLK=2*(X(i)-X(SectorIndexs(SectorIndex)))/(X(SectorIndexs(SectorIndex+1))-X(SectorIndexs(SectorIndex)
3、))一1Yl(i)=Conf(7*Sectorindex+0)+Conf(7*Sectorindex+1)*XLK+Conf(7*Sectorindex+2)*(2*XLK人2・1)+Conf(7*Sectorindex+3)*(4*XLK人3・3*XLK)NextReturnY1EndFunctionPrivateFunctionSearchSectorIndex(ByValIndexAsInteger,ByVaiSectorlndexs()AsInteger)AsIntegerDimiAsIntegerFo
4、ri=OToUBound(Sectorlndexs)・1IfIndex>=Sectorlndexs(i)AndIndex<=Sectorlndexs(i+1)ThenReturniEndIfIfIndex>=Sectorlndexs(i)AndSectorlndexs(i+1)=0Then。环狀ReturniEndIfNextEndFunctionPrivateFunctionSearchIndex(ByValXIAsSingle,ByVaiX()AsSingle)AsIntegerDimiAsIntegerF
5、ori=0ToUBound(X)IfXl>=X(i)AndXI<=X(i+1)ThenReturniEndIfNextEndFunction'样条函数拟合计算,返冋样条函数系数'x-x序列y-序列'Sectorlndexs-分段点索引序列'技术要求:双端在X的分段,X0和Xn是分段的首末点PrivateFunctionFitBySpline(ByValX()AsSingle,ByVaiY()AsSingle,ByVaiSectorlndexs()AsInteger)AsArrayDimSectorCount=U
6、Bound(Sectorlndexs)'M个点将差出M-l段DimTotalRowAsInteger=(SectorCount)*7-3DimMatrixA(TotalRow-1,TotalRow-1),MatrixB(TotalRow-1)AsSingleDimCurrentSectorlndex,CurrentPointlndex,CurrentPointlndexPerSectorAsIntegerDimHl,XLKAsSingle,PointCountPerSectorAsIntegerDimAl,A2
7、,A3,A4AsSingleForCurrentSectorlndex=0ToSectorCount-1Hl=1/(X(Sectorlndexs(CurrentSectorIndex+1))・X(SectorIndexs(CurrentSectorIndex)))PointCountPerSector=SectorIndexs(CurrentSectorIndex+1)-Sectorlndexs(CurrentSectorlndex)'双端在X上,仅计入一个ForCurrentPointlndexPerSect
8、or=0ToPointCountPerSector-1CurrentPointlndex=CurrentPointlndexPerSector+Sectorlndexs(CurrentSectorlndex)XLK=2*(X(CurrentPointlndex)-X(SectorIndexs(CurrentSectorIndex)))*Hl-1Al=1A2=XLKA3=2*XLK八2・