www.gusucode.com > matlab通信工程仿真源码(张德丰等编著)程序书籍 > matlab_code/matlab通信工程仿真源码(张德丰等编著)/第9章/li9_25.m
clear all; x=-1:0.01:1; y=1./(1+9*x.^2); plot(x,y,'b'); hold on; %原始函数曲线 xs=[-1 -0.4 -0.1 0 0.3 0.7]; %样本位置 ys=1./(1+9*xs.^2); plot(xs,ys,'rp'); hold on; %样本点 xi=-1:0.07:1; %插值位置 yi=interp1(xs,ys,xi,'linear','extrap'); %线性插值,并外插 plot(xi,yi,'m.'); yi=interp1(xs,ys,xi,'nearest'); %邻近点插值 plot(xi,yi,'-.'); yi=interp1(xs,ys,xi,'pchip'); %立方插值 plot(xi,yi,'+'); yi=interp1(xs,ys,xi,'spine'); %样条插值; plot(xi,yi,'s'); legend('原始函数','样本点','线性插值','邻近点插值','立方插值','样条插值');