matlab插值法实例_第1页
matlab插值法实例_第2页
matlab插值法实例_第3页
matlab插值法实例_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Several Typical Interpolation in MatlabLagrange InterpolationSuppos ing:x144169225y121315If x=175, while y=?Solution :Lagrange Interpolation in Matlab: function y=lagra nge(xO,yO,x);n=le ngth(xO);m=le ngth(x);for i=1:mz=x(i);s=0.0;for k=1: np=1.0;for j=1: nif j=k p=p*(z-xO(j)/(xO(k)-xO(j);endends=p*

2、yO(k)+s;endy(i)=s;endin put:x0=144 169 225y0=12 13 15y=lagra nge(x0,y0,175)obta in the an swer:x0 =144169225y0 =121315y =13.2302Spline InterpolationSuppos ing:x14916厂 Vx1234Resolve the cubic spline function s (x)Solution :In put x= 1 4 9 6 ; y= 1 4 9 6 ; x= 1 4 9 6 ; pp=spli ne(x,y)PP =form: ppbreak

3、s: 1 4 6 9coefs: 3x4 doublepieces: 3order: 4dim: 1output : pp.coefsans =-0.05000.5333-0.81671.0000-0.05000.08331.03332.0000-0.0500-0.21670.76674.0000It shows the coefficie nts of cubic spli ne polyno mial , so:320.0008(x -1) -0.0254(x-1)0.4024(x - 1)1,仁 x _ 4,32S (x) =0.0008(x-4) -0.0183(x-4)0.2714(

4、x -4) 2,4 乞 x _ 9,320.0008(x-9) - 0.0063(x-9)0.1484(x - 9) 3,9 乞 x 一 16,Newton s InterpolationSuppos ing:x149Vx123Resolve 5 6Soluti on:Newt on s In terpolatiorim matlab :fun ctio n yi=newin t(x,y,xi);n=len gth(x);ny=le ngth(y);if n=nyerrorendY=zeros (n );Y(:,1)=y:for k=1: n-1for i=1: n-kif abs(x(i+k

5、)_x(i)epserrorendY(i,k+1)=(Y(i+1,k)-Y(i,k)/(x(i+k)-x(i);endendm=le ngth(xi);yi=zeros(1,m);for i=1: n;z=on es(1,m);for k=1:i-1;z=z.*(xi-x(k);endyi=yi+Y(1,i)* z;end in put:x=1 4 9;y=1 2 3;xi=5 6;yi=n ewi nt(x,y,xi);operate the program and obta in the an swer: yi=2.26672.5000The difference between seve

6、ral One-dimensional Interpolations like nearest、 linear、 、 Xspline、 cubicSupposing x 0,4, y = sin(x).*exp(-x/5),plot the figure .Soluti on:program of MATLAB :x = 0:1:4*pi;y = sin( x).*exp(-x/5);xi = 0:0.1:4*pi;y1 = in terp1(x, y, xi, n earest);y2 = in terp1(x, y, xi, li near);y3 = in terp1(x, y, xi, spli ne);y4 = in terp1(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);operate the program

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论