您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 纺织服装 > 2、拉格朗日插值的matlab实现
2、拉格朗日插值实例:根据下面的数据点求出其拉格朗日插值格式,并计算当x=1.6时y的值。x00.51.01.52.02.53.0y00.47940.81450.99750.90930.59850.1411function[f,f0]=Language(x,y,x0)%求已知数据点的拉格朗日插值多项式%已知数据点的x坐标向量:x%已知数据点的y坐标向量:y%插值点的x坐标:x0%求得的拉格朗日插值多项式:f%x0处的插值:f0symst;if(length(x)==length(y))n=length(x);elsedisp('x和y的维数不相等!');return;end%检错f=0.0;for(i=1:n)l=y(i);for(j=1:i-1)l=l*(t-x(j))/(x(i)-x(j));end;for(j=i+1:n)l=l*(t-x(j))/(x(i)-x(j));%计算拉格朗日基函数end;f=f+l;%计算拉格朗日插值函数simplify(f);%化简endf0=subs(f,'t',x0);%计算插值点的函数值运行程序;x=0:0.5:3;y=[00.47940.84150.99750.90930.59850.1411];[f,f0]=Language(x,y,1.6)%计算输出的拉格朗日插值多项式%计算x=1.6时的插值输出值f0运行结果f=-799/3125*t*(t-1)*(t-3/2)*(t-2)*(t-5/2)*(t-3)+561/500*t*(t-1/2)*(t-3/2)*(t-2)*(t-5/2)*(t-3)-133/75*t*(t-1/2)*(t-1)*(t-2)*(t-5/2)*(t-3)+3031/2500*t*(t-1/2)*(t-1)*(t-3/2)*(t-5/2)*(t-3)-399/1250*t*(t-1/2)*(t-1)*(t-3/2)*(t-2)*(t-3)+1411/112500*t*(t-1/2)*(t-1)*(t-3/2)*(t-2)*(t-5/2)f0=0.9996
本文标题:2、拉格朗日插值的matlab实现
链接地址:https://www.777doc.com/doc-6063940 .html