资源描述:
《matlab插值法实例》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、SeveralTypicalInterpolationinMatlabLagrangeInterpolationSupposing:x144169225y121315Ifx=175,whiley=?Solution:LagrangeInterpolationinMatlab:functiony=lagrange(x0,y0,x);n=length(x0);m=length(x);fori=1:mz=x(i);s=0.0;fork=1:np=1.0;forj=1:nifj~=kp=p*(z-x0(j))/(x0(k)-x0(j));endends=p*y0(k)+s;endy(i)=s;e
2、ndinput:x0=[144169225]y0=[121315]y=lagrange(x0,y0,175)obtaintheanswer:x0=144169225y0=121315y=13.2302SplineInterpolationSupposing:x149161234Resolvethecubicsplinefunctions(x)Solution:Inputx=[1496];y=[1496];x=[1496];pp=spline(x,y)pp=form:'pp'breaks:[1469]coefs:[3x4double]pieces:3order:4dim:1output:p
3、p.coefsans=-0.05000.5333-0.81671.0000-0.05000.08331.03332.0000-0.0500-0.21670.76674.0000Itshowsthecoefficientsofcubicsplinepolynomial,so:S(x)=Newton’sInterpolationSupposing:x149123ResolveSolution:Newton’sInterpolationinmatlab:functionyi=newint(x,y,xi);n=length(x);ny=length(y);ifn~=nyerrorendY=zer
4、os(n);Y(:,1)=y';fork=1:n-1fori=1:n-kifabs(x(i+k)-x(i))5、26672.5000ThedifferencebetweenseveralOne-dimensionalInterpolationslike`nearest`、`linear`、`spline`、`cubic`Supposing,y=sin(x).*exp(-x/5),plotthefigure.Solution:programofMATLAB:x=0:1:4*pi;y=sin(x).*exp(-x/5);xi=0:0.1:4*pi;y1=interp1(x,y,xi,'nearest');y2=interp1(x,y,xi,'linear');y3=interp1(x,y,xi,'sp
6、line');y4=interp1(x,y,xi,'cubic');plot(x,y,'o',xi,y1,'g-',xi,y2,'r:',xi,y3,'k-.',xi,y4,'b--');legend('Original','Nearest','Linear','Spline','Cubic');operatetheprogramandobtainthefigure:(Itshowsthatthesmoothnessof'nearest'istheworstand`cubic`isthebest.)