資源描述:
《matlab插值算法程序集》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Matlab插值算法程序集一、插值算法1.Atkenfunctionf=Atken(x,y,x0)symst;if(length(x)==length(y))n=length(x);elsedisp('x和y的維數(shù)不相等!');return;end%檢錯(cuò)y1(1:n)=t;%符號函數(shù)數(shù)組要賦初值for(i=1:n-1)for(j=i+1:n)y1(j)=y(j)*(t-x(i))/(x(j)-x(i))+y(i)*(t-x(j))/(x(i)-x(j));endy=y1;simplify(y1);endif(nargin==3)f=subs(y1(n),'t',x0);%計(jì)算插值點(diǎn)的函數(shù)
2、值elsesimplify(y1(n));%化簡f=collect(y1(n));%將插值多項(xiàng)式展開f=vpa(f,6);%將插值多項(xiàng)式的系數(shù)化成6位精度的小數(shù)end2.BSamplefunctionf0=BSample(a,b,n,y,y_1,y_N,x0)f0=0.0;h=(b-a)/n;c=zeros(n+3,1);b=zeros(n+1,1);fori=0:n-1if(a+i*h<=x0)&&(a+i*h+h>=x0)index=i;break;endend%找到x0所在區(qū)間A=diag(4*ones(n+1,1));I=eye(n+1,n+1);AL=[I(2:n+1,:);z
3、eros(1,n+1)];AU=[zeros(1,n+1);I(1:n,:)];A=A+AL+AU;%形成系數(shù)矩陣fori=2:nb(i,1)=6*y(i);endb(1)=6*y(1)+2*h*y_1;b(n+1)=6*y(n+1)-2*h*y_N;d=followup(A,b);%用追趕法求出系數(shù)c(2:n+2)=d;c(1)=c(2)-2*h*y_1;%c(-1)c(n+3)=c(3)+2*h*y_N;%c(n+1)x1=(a+index*h-h-x0)/h;m1=c(index+1)*(-((abs(x1))^3)/6+(x1)^2-2*abs(x1)+4/3);x2=(a+in
4、dex*h-x0)/h;m2=c(index+2)*((abs(x2))^3/2-(x2)^2+2/3);x3=(a+index*h+h-x0)/h;m3=c(index+3)*((abs(x3))^3/2-(x3)^2+2/3);x4=(a+index*h+2*h-x0)/h;m4=c(index+4)*(-((abs(x4))^3)/6+(x4)^2-2*abs(x4)+4/3);f0=m1+m2+m3+m4;%求出插值3.DCSfunctionf=DCS(x,y,x0)symst;if(length(x)==length(y))n=length(x);c(1:n)=0.0;else
5、disp('x和y的維數(shù)不相等!');return;endc(1)=y(1);for(i=1:n-1)for(j=i+1:n)y1(j)=(x(j)-x(i))/(y(j)-y(i));endc(i+1)=y1(i+1);y=y1;endf=c(n);for(i=1:n-1)f=c(n-i)+(t-x(n-i))/f;f=vpa(f,6);if(i==n-1)if(nargin==3)f=subs(f,'t',x0);elsef=vpa(f,6);endendend;4.DHfunctionfz=DH(x,y,x0,y0,zx,zy,zxy)n=length(x);m=length(y)
6、;fori=1:nif(x(i)<=x0)&&(x(i+1)>=x0)index_x=i;break;endend%找到x0所在區(qū)間fori=1:mif(y(i)<=y0)&&(y(i+1)>=y0)index_y=i;break;endend%找到y(tǒng)0所在區(qū)間hx=x(index_x+1)-x(index_x);hy=y(index_y+1)-y(index_y);tx=(x0-x(index_x))/hx;%插值坐標(biāo)歸一化ty=(y0-y(index_y))/hy;%插值坐標(biāo)歸一化Hl=[(1-tx)^2*(1+2*tx)tx*tx*(3-2*tx)tx*(1-tx)^2tx*tx*
7、(tx-1)];%左向量Hr=[(1-ty)^2*(1+2*ty);ty*ty*(3-2*ty);ty*(1-ty)^2;ty*ty*(ty-1)];%右向量C=[Z(index_x,index_y)Z(index_x,index_y+1)zy(index_x,index_y)...zy(index_x,index_y+1);Z(index_x+1,index_y)Z(index_x+1,index_y+1)zy(index_x+1