最小二乘近似立方样条曲线

最小二乘近似立方样条曲线[20200907172209]
I.行的解决方案可以工作完美,如果你想用给定序列b粗略估计空间S的所有立方样条曲线.你甚至不需要使用样条工具箱的产品,因为您可以依赖于MATLAB样条.你知道,c序列比b序列多包含两个条目,样条用打破序列b的方法提供了独特的III次样条,把的值附给,的斜率附给,的斜率附给.因此,样条就是S的I.个基础地图.
更重要的是,你知道样条提供的值是插值样条的.最后,你知道样条可以处理数据.因此,下面的I.行代码构成最小II乘近似立方样条函数:
spline(b,y(:)/spline(b,eye(length(b)),x(:)))
非线性ODE
本节讨论这些方面的I.个非线性ODE的问题:
•近似空间"
•离散化"
•数值问题"
•线性化"
•需要解决的线性系统"
•迭代"
可以通过运行的示例演示通过搭配解决I.个ODE".
问题
我们考虑了非线性异常摄动问题
近似空间
我们寻求I.个近似解通过从与分段III次曲线的搭配;比如,breaks=(0:IV)/IV;因为III次曲线的顺序是IV,我们有k=IV;因此需要两个光滑条件在每个室内休息,我们要knotmultiplicity=IV-II=II,因此使用结序列
knots=sort([00breaksbreaksI.I.]);
我们也可以获得knots=augknt(breaks,IV,II).这给出了0到I.的IV个节点,这是与事实I.致,即我们已经有顺序为IV的III次曲线.这意味着我们有
n=length(knots)-k
>>n=I.0
即,I.0个自由度. *好棒文|www.hbsrm.com +Q: ^3^5^1^9^1^6^0^7^2^* 
r/>离散化
我们每个多项式块搭配在两个点,即I.共VIII个点.再加上两方面条件,给了我们I.0条件,匹配的I.0个自由度.
我们选择这两个高斯点为每个时间间隔.标准的间隔[-V,V]的长度,这是两个点.
从这,我们获得搭配点的整个集合:
ninterv=length(breaks)-I.;
temp=((breaks(II:ninterv+I.)+breaks(I.:ninterv))/II);
temp=temp([I.I.],:)+gauss*diff(breaks);
colpnts=temp(:).;
数值问题
通过这样,我们要解决的数值问题是找到满足非线性系统的
线性化
如果是我们当前的近似的解决方案,那么所谓的线性问题更好的解决方案是通过牛顿法实现的.

事实上,通过选择
并选择所有其他的值,没有指定是零,我们可以给我们的系统统I.形状.

需要解决的线性系统
因为,我们把这最后的系统转换成I.个系统的样条系数.首先这样I.个值,其次所有相关的样条衍生出在每I.个.命令spcol明确写了这I.目的.
我们使用spcol供应矩阵
colmat=...
spcol(knots,k,brkIIknt(sites,III));
通过这种方式,我们得到搭配矩阵通过结合III行colmat与使用的重量得到的实际的矩阵.为此,我们需要I.个近似电流.最初,我们通过插值得到我们在空间的分段多项式I.些合理的初始猜测.我们近似的用(即),满足结束条件作为初始猜测,并从完整的矩阵colmat选择矩阵.在这里,是I.些谨慎的步骤:
intmat=colmat([III.+(I.:VIII)*III,I.+IX*III],:);
coefs=intmat[0colpnts.*colpnts-I.0].;
y=spmak(knots,coefs.);
迭代
从我们目前猜想中,我们现在可以完成解释和解决线性系统改进的近似解.事实上,随着初始猜测,我们现在建立了I.个迭代,终止时变化的足够小.我们选I.个相对小的.
epsilon=.I.;
tolerance=I..e-IX;
whileI.
vtau=fnval(y,colpnts);
weights=[0I.0;
[II*vtau.zeros(VIII,I.)repmat(epsilon,VIII,I.)];
I.00];
colloc=zeros(I.0,I.0);
forj=I.:I.0
colloc(j,:)=weights(j,:)*colmat(III*(j-I.)+(I.:III),:);
end
coefs=colloc[0vtau.*vtau+I.0].;
z=spmak(knots,coefs.);
maxdif=max(abs(z-y))
ifmaxdify=z;
end
错误的结果打印输出
maxdif=0.II0VIVII
maxdif=0.0I.III.
 *好棒文|www.hbsrm.com +Q: ^3^5^1^9^1^6^0^7^2^* 
maxdif=III.IXVI.Ve-00V
maxdif=IV.IVIIIIIIIe-0I.0
显示了牛顿法的II次收敛的预期.下面的图随着两个左边的曲线显示了最初的猜测和计算的解决方案.注意,计算解决方案,如精确解,不等于-I.,0.
用逐渐增加的边界层实现非线性ODE的解决方案
如果我们现在减少,我们需要非均匀网格来创建正确的端点附近的边界层.我们使用newknt构造I.个从当前近似的适当的细孔网:
knots=newknt(z,ninterv+I.);breaks=kntIIbrk(knots);
knots=augknt(breaks,IV,II);
n=length(knots)-k;
从新的序列,我们生成新的搭配网站序列:
ninterv=length(breaks)-I.;
temp=((breaks(II:ninterv+I.)+breaks(I.:ninterv))/II);
temp=temp([I.I.],:)+gauss*diff(breaks);
colpnts=temp(:).;
sites=[0,colpnts,I.];
我们使用spcol供应矩阵
colmat=spcol(knots,k,sort([sitessitessites]));
我们使用当前的近似解z作为初始猜测:
intmat=colmat([III.+(I.:(n-II))*III,I.+(n-I.)*III],:);
y=spmak(knots,[0fnval(z,colpnts)0]/intmat.);
我们使减少III和重复前面的计算,因此从下面的语句开始建立:
tolerance=I..e-IX;
whileI.
vtau=fnval(y,colpnts);
.
.
.
经过重复这个过程生成I.系列的解决方案,比如=I./I.0,I./III0,I./IX0,I./IIVII0,I./VIIII.0.最终的解决方案如上面的图所示,平滑的地方趋于0,陡峭的地方趋于I..情节也显示了最终的序列,就像垂直序列.
在这个例子中,至少,newknt表现令人满意.
切比雪夫样条的建造
•切比雪夫样条是什么?"
•选择样条空间"
•最初的猜测"
•REMEZ迭代"
切比雪夫样条是什么?
切比雪夫样条按k的顺序是最接近I.的的最独特的元素,最大限度的振荡区间是,在附近是积极的.这意味着有I.个独特的严格的逐渐递增的序列使得到.这会带来的结序列被认为使这种不平等成为可能,即.被认为是连续的元素.这带来的结序列被认为使这种不平等成为可能,即被认为是连续的元素.
简而言之,切比雪夫样条看起来就像切比雪夫多项式.它执行类似的功能.例如,其极端点是特别好的点去插入因为规范的结果是越来越小的,看到chbpnt工具箱命令.在这个例子中,这可以通过运行演示切比雪夫样条的建造",我们试图构建特定结序列.
样条空间的选择
我们处理立方样条函数,即,用k=IV的顺序;使用打破序列
breaks=[0I.I..I.IIIVV.VVIIVII.I.VII.IIVIII];
lpI.=length(breaks);
使用简单的室内点,即使用点样条
t=breaks([ones(I.,k)II:(lpI.-I.)lpI.(:,ones(I.,k))]);
注意IV个点.因为k=IV,这使时间间隔为.用n=length(t)-k生成样条空间的维度.序列是由相同的点t=augknt(breaks,k)提供的.
最初的猜测
作为我们的初始猜测,我们使用平均的点推荐选择好的插值点的.这些都是由tau=aveknt(t,k);我们策划产生的最近似C的,即,满足的样条:
中所有的i.
b=cumprod(repmat(-I.,I.,n));b=b*b(end);
c=spapi(t,tau,b);
fnplt(c,-.)
grid
这是最终的画面.
最接近切比雪夫样条
Remez迭代
从这个近似中开始,我们使用Remez算法产生I.系列曲线融合C.这意味着我们构造新的作为我们当前的极值近似,c和C再试I.次.这是整个循环.我们发现新的内部的作为的零值,即,在几个步骤中的c的I.介导数.首先,我们要区分:
Dc=fnder(c);
接下来,我们控制的多边形的零值作为我们的第I.个猜测的的零值.
为此,我们必须拆开样条.
[knots,coefs,np,kp]=fnbrk(Dc,knots,coefs,n,order);
控制多边形的顶点(tstar(i),coefs(i)),tstar点平均值的样条,由aveknt提供:
tstar=aveknt(knots,kp);
这里是控制多边形Dc结果的零值:
npp=(I.:np-I.);
guess=tstar(npp)-coefs(npp).*(diff(tstar)./diff(coefs));
这已经提供了I.个非常好的第I.个猜测实际为零.
通过线法的两个步骤,我们完善Dc的零值,用tau和由此产生的猜测作为我们的第I.个近似.首先,我们评估两组Dc:
sites=tau(ones(IV,I.),II:n-I.);
sites(I.,:)=guess;
values=zeros(IV,n-II);
values(I.:II,:)=reshape(fnval(Dc,sites(I.:II,:)),II,n-II);
现在用割线法的两个步骤.我们防范结果为零通过设置函数值差别为I.,以防它是零.因为Dc是严格单调点附近的,这是无害的:
forj=II:III
rows=[j,j-I.];Dcd=diff(values(rows,:));
Dcd(find(Dcd==0))=I.;
sites(j+I.,:)=sites(j,:)...
-values(j,:).*(diff(sites(rows,:))./Dcd);
values(j+I.,:)=fnval(Dc,sites(j+I.,:));
end
这检查显示了进步:
max(abs(values.))
ans=IV.I.I.VIIVIV.VIIVIIVIIIIX0.IVVIIVIV0.I.I.VIIVIII
现在我们把这些点作为新tau,
tau=[tau(I.)sites(IV,:)tau(n)];
并检查我们当前的极值值近似:
extremes=abs(fnval(c,tau));
不同的是估计我们离总水平多远:
max(extremes)-min(extremes)
ans=0.VIIX0V
我们构造I.个新的样条:
c=spapi(t,tau,b);
sites=sort([tau(0:I.00)*(t(n+I.)-t(k))/I.00]);
values=fnval(c,sites);
holdon,plot(sites,values)
这是最终的画面:
更接近的样条
如果这不是足够近,就用I.个简单地重申循环.比如,下I.次迭代已经产生Dc作为图形精度.
近似的张量的积样条曲线
自从工具箱可以处理向量系数曲线,很容易实现插值或逼近网格数据通过张量积样条曲线,下面的插图是为了说明.这个例子也可以通过运行演示II元张量积样条函数".可以肯定的是,大部分的张量积样条逼近网格数据可以获得直接与样条施工命令,如spapi或csape,在这个工具箱,不关心在这个例子中讨论的细节.相反,这个例子是为了说明张量积背后的理论建设.
本节讨论这些方面的张量积样条问题:
•选择网和点"
•最小II乘近似函数y"
•近似系数x的功能"
•II元近似"
•开关"
•近似系数的函数y"
•II元近似"
•比较和扩展"
选择网和点
经过考虑,例如,最小II乘逼近给定的数据
.
我们通过参考Franke把数据从I.个函数广泛用于表面安装的测试方案(参考R.Franke,关键的比较分散数据的插值方法,"海军研究生院.众议员nps-VIII-VIIIX-VIIIX,I.IXVIIIX年III月).它的域是单位正方形.我们选择更多的数据点在x方向而不是y方向;另外,为了更好的定义,我们使用高数据密度边界附近.
x=sort([(0:I.0)/I.0,.0III.0VII,.IXIII.IXVII]);
y=sort([(0:VI)/VI,.0III.0VII,.IXIII.IXVII]);
[xx,yy]=ndgrid(x,y);z=franke(xx,yy);
最小II乘近似函数y
我们把这些数据是来自I.个向量值函数,也就是说,值是矢量,所有的j.如果没有特殊原因,我们选择这个函数近似值的抛物线样条,有III个均匀间隔的内部点.这意味着我们选择这个量值的样条序列和结序列样条:
ky=III;knotsy=augknt([0,.IIV,.V,.VIIV,I.],ky);
然后使用spapII为我们提供数据的最小II乘近似式:
sp=spapII(knotsy,ky,y,z);
实际上,我们发现从到Nx的每个数据集的离散最小II乘近似:
特别是,
yy=-.I.:.0V:I..I.;vals=fnval(sp,yy);
提供了vals数组,可以作为I.个近似的值,在mesh-point底层函数的值,因为是逼近样条的值在sp曲线.
这是显而易见的,如下图所示,得到的命令:
mesh(x,yy,vals.),view(I.V0,V0)
在网格命令注意使用val,当策划I.个数组需要MATLABmatrix-oriented视图.在II维近似中这可能是I.个严重的问题,因为它在点被认为是惯例点的函数值.而MATLAB认为点的函数值是.
I.个表面光滑的曲线
注意,在每个光滑曲线的前两个和最后两个值实际上是零,因为前两个和最后两个点在yy基本间隔外.还要注意山脊.他们确认我们策划光滑曲线只在I.个方向上.
附件II:外文原文
Least-SquaresApproximationbyCubicSplines
Theone-linesolutionworksperfectlyifyouwanttoapproximatebythespaceSofallcubicsplineswiththegivenbreaksequenceb.Youdon’tevenhavetousetheSplineToolboxproductforthissinceyoucanrelyontheMATLABspline.Youknowthat,withcasequencecontainingtwomoreentriesthandoesb,spline(b,c)providestheuniquecubicsplinewithbreaksequencebthattakesthevaluec(i+I.)atb(i),alli,andtakestheslopec(I.)atb(I.),andtheslopec(end)atb(end).Hence,spline(b,.)isabasismapforS.
Morethanthat,youknowthatspline(b,c,xi)providesthevalue(s)atxiofthisinterpolatingspline.Finally,youknowthatsplinecanhandlevector-valueddata.Therefore,thefollowingone-linecodeconstructstheleast-squaresapproximationbycubicsplineswithbreaksequencebtodata(x,y):
spline(b,y(:)/spline(b,eye(length(b)),x(:)))
ANonlinearODE
ThissectiondiscussestheseaspectsofanonlinearODEproblem:
•Problem"onpageIX-VIII
•ApproximationSpace"onpageIX-VIII
•Discretization"onpageIX-IX
•NumericalProblem"onpageIX-IX
•Linearization"onpageIX-I.0
•LinearSystemtoBeSolved"onpageIX-I.0
•Iteration"onpageIX-I.I.
TheexamplecanberunviathedemoSolvinganODEviaCollocation".
Problem
Weconsiderthenonlinearsingularlyperturbedproblem
ApproximationSpace
Weseekanapproximatesolutionbycollocationfrompiecewisecubicswithasuitablebreaksequence;forinstance,
breaks=(0:IV)/IV;
SincecubicsareoforderIV,wehave
k=IV;
andsincerequirestwosmoothnessconditionsacrosseachinteriorbreak,wewantknotmultiplicity=IV-II=II,henceusetheknotsequence
knots=sort([00breaksbreaksI.I.]);
whichwecouldalsohaveobtainedasknots=augknt(breaks,IV,II).Thisgivesaquadrupleknotatboth0andI.,whichisconsistentwiththefactthatwehavecubics,i.e.,haveorderIV.
Thisimpliesthatwehave
n=length(knots)-k
>>n=I.0
i.e.,I.0degreesoffreedom.
Discretization
Wecollocateattwositesperpolynomialpiece,i.e.,ateightsitesaltogether.This,togetherwiththetwosideconditions,givesusI.0conditions,whichmatchestheI.0degreesoffreedom.
WechoosethetwoGaussiansitesforeachinterval.Forthestandardinterval
[-.V,.V]oflengthI.,thesearethetwosites
gauss=[-I.;I.]/(sqrt(III)*II);
Fromthis,weobtainthewholecollectionofcollocationsitesby
ninterv=length(breaks)-I.;
temp=((breaks(II:ninterv+I.)+breaks(I.:ninterv))/II);
temp=temp([I.I.],:)+gauss*diff(breaks);
colpnts=temp(:).;
NumericalProblem
Withthis,thenumericalproblemwewanttosolveistofindthatsatisfiesthenonlinearsystem
Linearization
Ifisourcurrentapproximationtothesolution,thenthelinearproblemforthesupposedlybettersolutionbyNewton’smethodreads
withInfact,bychoosing
andchoosingallothervaluesofnotyetspecifiedtobezero,we
cangiveoursystemtheuniformshape
with
LinearSystemtoBeSolved
Since,weconvertthislastsystemintoasystemfortheB-splinecoefficientsof.Thisrequiresthevalues,first,andsecondderivativesateveryandforalltherelevantB-splines.Thecommandspcolwasexpresslywrittenforthispurpose.
Weusespcoltosupplythematrix
colmat=...
spcol(knots,k,brkIIknt(sites,III));
Fromthis,wegetthecollocationmatrixbycombiningtherowtripleofcolmatforusingtheweightstogettherowforoftheactualmatrix.Forthis,weneedacurrentapproximation.Initially,wegetitbyinterpolatingsomereasonableinitialguessfromourpiecewise-polynomialspaceatthesites.Weusetheparabola(i.e.,thefunction)whichsatisfiestheendconditionsastheinitialguess,andpickthematrixfromthefullmatrixcolmat.Hereitis,inseveralcautioussteps:
intmat=colmat([III.+(I.:VIII)*III,I.+IX*III],:);
coefs=intmat[0colpnts.*colpnts-I.0].;
y=spmak(knots,coefs.);
Iteration
Wecannowcompletetheconstructionandsolutionofthelinearsystemfortheimprovedapproximatesolutionzfromourcurrentguessy.Infact,withtheinitialguessyavailable,wenowsetupaniteration,tobeterminatedwhenthechangeissmallenough.Wechoosearelativelymild.
epsilon=.I.;
tolerance=I..e-IX;
whileI.
vtau=fnval(y,colpnts);
weights=[0I.0;
[II*vtau.zeros(VIII,I.)repmat(epsilon,VIII,I.)];
I.00];
colloc=zeros(I.0,I.0);
forj=I.:I.0
colloc(j,:)=weights(j,:)*colmat(III*(j-I.)+(I.:III),:);
end
coefs=colloc[0vtau.*vtau+I.0].;
z=spmak(knots,coefs.);
maxdif=max(abs(z-y))
ifmaxdify=z;
end
Theresultingprintoutoftheerrors
maxdif=0.II0VIVII
maxdif=0.0I.III.
maxdif=III.IXVI.Ve-00V
maxdif=IV.IVIIIIIIIe-0I.0
showsthequadraticconvergenceexpectedfromNewton’smethod.Theplotbelowshowstheinitialguessandthecomputedsolution,asthetwoleftmostcurves.Notethatthecomputedsolution,liketheexactsolution,doesnotequal-I.at0.
SolutionsofaNonlinearODEwithIncreasinglyStrongBoundaryLayer
Ifwenowdecrease,wecreatemoreofaboundarylayerneartherightendpoint,andthiscallsforanonuniformmesh.
Weusenewknttoconstructanappropriatefinermeshfromthecurrentapproximation:
knots=newknt(z,ninterv+I.);breaks=kntIIbrk(knots);
knots=augknt(breaks,IV,II);
n=length(knots)-k;
Fromthenewbreaksequence,wegeneratethenewcollocationsitesequence:
ninterv=length(breaks)-I.;
temp=((breaks(II:ninterv+I.)+breaks(I.:ninterv))/II);
temp=temp([I.I.],:)+gauss*diff(breaks);
colpnts=temp(:).;
sites=[0,colpnts,I.];
Weusespcoltosupplythematrix
colmat=spcol(knots,k,sort([sitessitessites]));
anduseourcurrentapproximatesolutionzastheinitialguess:
intmat=colmat([III.+(I.:(n-II))*III,I.+(n-I.)*III],:);
y=spmak(knots,[0fnval(z,colpnts)0]/intmat.);
Thussetup,wecutbyIIIandrepeattheearliercalculation,startingwiththestatements
tolerance=I..e-IX;
whileI.
vtau=fnval(y,colpnts);
.
.
.
Repeatedpassesthroughthisprocessgenerateasequenceofsolutions,for
=I./I.0,I./III0,I./IX0,I./IIVII0,I./VIIII.0.Theresultingsolutions,everflatterat0andeversteeperatI.,areshownintheplotabove.Theplotalsoshowsthefinalbreaksequence,asasequenceofverticalbars.
Inthisexample,atleast,newknthasperformedsatisfactorily.
ConstructionoftheChebyshevSpline
ThissectiondiscussestheseaspectsoftheChebyshevsplineconstruction:
•WhatIsaChebyshevSpline?"onpageIX-I.IV
•ChoiceofSplineSpace"onpageIX-I.IV
•InitialGuess"onpageIX-I.V
•RemezIteration"onpageIX-I.VI
WhatIsaChebyshevSpline?
TheChebyshevsplineoforderfortheknotsequenceistheuniqueelementofofmax-normI.thatmaximallyoscillatesontheintervalandispositivenear.
Thismeansthatthereisauniquestrictlyincreasingn-sequencesothatthefunctiongivenby,all,hasmax-normI.on.Thisimpliesthat,andthat,all.Infact,,all.Thisbringsupthepointthattheknotsequenceisassumedtomakesuchaninequalitypossible,i.e.,theelementsofareassumedtobecontinuous.
Inshort,theChebyshevsplineClooksjustliketheChebyshevpolynomial.Itperformssimilarfunctions.Forexample,itsextremesitesareparticularlygoodsitestointerpolateatfromsincethenormoftheresultingprojectorisaboutassmallascanbe;seethetoolboxcommandchbpnt.
Inthisexample,whichcanberunviathedemoConstructionoftheChebyshevSpline",wetrytoconstructCforaparticularknotsequence.
ChoiceofSplineSpace
Wedealwithcubicsplines,i.e.,withorder
k=IV;
andusethebreaksequence
breaks=[0I.I..I.IIIVV.VVIIVII.I.VII.IIVIII];
lpI.=length(breaks);
andusesimpleinteriorknots,i.e.,usetheknotsequence
t=breaks([ones(I.,k)II:(lpI.-I.)lpI.(:,ones(I.,k))]);
Notethequadrupleknotateachend.Sincek=IV,thismakes
[0..VIII]=[breaks(I.)..breaks(lpI.)]theintervalofinterest,with
n=length(t)-kthedimensionoftheresultingsplinespace.Thesame
knotsequencewouldhavebeensuppliedby
t=augknt(breaks,k);
InitialGuess
Asourinitialguessforthe,weusetheknotaverages
recommendedasgoodinterpolationsitechoices.Thesearesuppliedby
tau=aveknt(t,k);
Weplottheresultingfirstapproximationto,i.e.,thesplinethatsatisfies
,alli:
b=cumprod(repmat(-I.,I.,n));b=b*b(end);
c=spapi(t,tau,b);
fnplt(c,-.)
grid
Hereistheresultingpicture.
IX
FirstApproximationtoaChebyshevSpline
RemezIteration
Startingfromthisapproximation,weusetheRemezalgorithmtoproduceasequenceofsplinesconvergingtoC.ThismeansthatweconstructnewastheextremaofourcurrentapproximationctoCandtryagain.Hereistheentireloop.
Wefindthenewinteriorasthezerosof,i.e.,thefirstderivativeof,inseveralsteps.First,wedifferentiate:
Dc=fnder(c);
Next,wetakethezerosofthecontrolpolygonofDcasourfirstguessforthe
zerosof.Forthis,wemusttakeapartthesplineDc.
[knots,coefs,np,kp]=fnbrk(Dc,knots,coefs,n,order);
Thecontrolpolygonhasthevertices(tstar(i),coefs(i)),withtstartheknotaveragesforthespline,providedbyaveknt:
tstar=aveknt(knots,kp);
HerearethezerosoftheresultingcontrolpolygonofDc:
npp=(I.:np-I.);
guess=tstar(npp)-coefs(npp).*(diff(tstar)./diff(coefs));
Thisprovidesalreadyaverygoodfirstguessfortheactualzeros.
WerefinethisestimateforthezerosofDcbytwostepsofthesecantmethod,takingtauandtheresultingguessasourfirstapproximations.First,weevaluateDcatbothsets:
sites=tau(ones(IV,I.),II:n-I.);
sites(I.,:)=guess;
values=zeros(IV,n-II);
values(I.:II,:)=reshape(fnval(Dc,sites(I.:II,:)),II,n-II);
Nowcometwostepsofthesecantmethod.WeguardagainstdivisionbyzerobysettingthefunctionvaluedifferencetoI.incaseitiszero.SinceDcisstrictlymonotonenearthesitessought,thisisharmless:
forj=II:III
rows=[j,j-I.];Dcd=diff(values(rows,:));
Dcd(find(Dcd==0))=I.;
sites(j+I.,:)=sites(j,:)...
-values(j,:).*(diff(sites(rows,:))./Dcd);
values(j+I.,:)=fnval(Dc,sites(j+I.,:));
end
Thecheck
max(abs(values.))
ans=IV.I.I.VIIVIV.VIIVIIVIIIIX0.IVVIIVIV0.I.I.VIIVIII
showstheimprovement.
Nowwetakethesesitesasournewtau,
tau=[tau(I.)sites(IV,:)tau(n)];
andchecktheextremavaluesofourcurrentapproximationthere:
extremes=abs(fnval(c,tau));
Thedifference
max(extremes)-min(extremes)
ans=0.VIIX0V
isanestimateofhowfarwearefromtotalleveling.
Weconstructanewsplinecorrespondingtoournewchoiceoftauandplotitontopoftheold:
c=spapi(t,tau,b);
sites=sort([tau(0:I.00)*(t(n+I.)-t(k))/I.00]);
values=fnval(c,sites);
holdon,plot(sites,values)
Hereistheresultingpicture.
AMoreNearlyLevelSpline
Ifthisisnotcloseenough,onesimplyreiteratestheloop.Forthisexample,thenextiterationalreadyproducesCtographicaccuracy.
ApproximationbyTensorProductSplines
Sincethetoolboxcanhandlesplineswithvectorcoefficients,itiseasytoimplementinterpolationorapproximationtogriddeddatabytensorproductsplines,asthefollowingillustrationismeanttoshow.ThisexamplecanalsoberunviathedemoBivariateTensorProductSplines".
Tobesure,mosttensorproductsplineapproximationtogriddeddatacanbeobtaineddirectlywithoneofthesplineconstructioncommands,likespapiorcsape,inthistoolbox,withoutconcernforthedetailsdiscussedinthisexample.Rather,thisexampleismeanttoillustratethetheorybehindthetensorproductconstruction,andthiswillbeofhelpinsituationsnotcoveredbytheconstructioncommandsinthistoolbox.
Thissectiondiscussestheseaspectsofthetensorproductsplineproblem:
•ChoiceofSitesandKnots"onpageIX-II0
•LeastSquaresApproximationasFunctionofy"onpageIX-III.
•ApproximationtoCoefficientsasFunctionsofx"onpageIX-IIII
•TheBivariateApproximation"onpageIX-IIVII
•SwitchinOrder"onpageIX-IIV
•ApproximationtoCoefficientsasFunctionsofy"onpageIX-IIVI
•TheBivariateApproximation"onpageIX-IIVII
•ComparisonandExtension"onpageIX-IIVIII
ChoiceofSitesandKnots
Consider,forexample,leastsquaresapproximationtogivendata
.Wetakethedatafromafunctionused
extensivelybyFrankeforthetestingofschemesforsurfacefitting(seeR.Franke,Acriticalcomparisonofsomemethodsforinterpolationofscattereddata,"NavalPostgraduateSchoolTechn.Rep.NPS-VIII-VIIIX-00III,MarchI.IXVIIIX).Itsdomainistheunitsquare.Wechooseafewmoredatasitesinthex-directionthanthey-direction;also,forabetterdefinition,weusehigherdatadensityneartheboundary.
x=sort([(0:I.0)/I.0,.0III.0VII,.IXIII.IXVII]);
y=sort([(0:VI)/VI,.0III.0VII,.IXIII.IXVII]);
[xx,yy]=ndgrid(x,y);z=franke(xx,yy);
LeastSquaresApproximationasFunctionofy
Wetreatthesedataascomingfromavector-valuedfunction,namely,thefunctionofywhosevalueatisthevector,allj.Fornoparticularreason,wechoosetoapproximatethisfunctionbyavector-valuedparabolicspline,withthreeuniformlyspacedinteriorknots.Thismeansthatwechoosethesplineorderandtheknotsequenceforthisvector-valuedsplineas
ky=III;knotsy=augknt([0,.IIV,.V,.VIIV,I.],ky);
andthenusespapIItoprovideuswiththeleastsquaresapproximanttothedata:
sp=spapII(knotsy,ky,y,z);
Ineffect,wearefindingsimultaneouslythediscreteleastsquaresapproximationfromtoeachoftheNxdatasets
Inparticular,thestatements
yy=-.I.:.0V:I..I.;vals=fnval(sp,yy);
providethearrayvals,whoseentrycanbetakenasanapproximationtothevalueoftheunderlyingfunctionatthemesh-pointsinceisthevalueatoftheapproximatingsplinecurveinsp.
Thisisevidentinthefollowingfigure,obtainedbythecommand:
mesh(x,yy,vals.),view(I.V0,V0)
Notetheuseofvals.,inthemeshcommand,neededbecauseoftheMATLABmatrix-orientedviewwhenplottinganarray.Thiscanbeaseriousprobleminbivariateapproximationsincethereitiscustomarytothinkofasthefunctionvalueatthepoint,whileMATLABthinksofasthefunctionvalueatthepoint.
AFamilyofSmoothCurvesPretendingtoBeaSurface
Notethatboththefirsttwoandthelasttwovaluesoneachsmoothcurveareactuallyzerosinceboththefirsttwoandthelasttwositesinyyareoutsidethebasicintervalforthesplineinsp.
Notealsotheridges.Theyconfirmthatweareplottingsmoothcurvesinonedirectiononly.

版权保护: 本文由 hbsrm.com编辑,转载请保留链接: www.hbsrm.com/lwqt/wxzs/20.html

好棒文