《拉格朗日插值matlab程序(共4页).docx》由会员分享,可在线阅读,更多相关《拉格朗日插值matlab程序(共4页).docx(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上拉格朗日插值的调用函数function y=lagrange(x0,y0,x)n=length(x0);m=length(x);for i=1:m z=x(i); L=0.0; for j=1:n T=1.0; for k=1:n if k=j T=T*(z-x0(k)/(x0(j)-x0(k); end end L=T*y0(j)+L; end y(i)=L;end四个图在一起:x=-1:0.05:1;y=1./(1+25*x.2);x0=-1:0.4:1;y0=1./(1+25*x0.2);y1=lagrange(x0,y0,x);x0=-1:0.2:1;y0=1
2、./(1+25*x0.2);y2= lagrange(x0,y0,x);x0=-1:0.1:1;y0=1./(1+25*x0.2);y3= lagrange(x0,y0,x);plot(x,y,-r)hold onplot(x,y1,-b,x,y2,-r,x,y3,-r)l5和fx在一起:x=-1:0.05:1;y=1./(1+25*x.2);x0=-1:0.4:1;y0=1./(1+25*x0.2);y1=lagrange(x0,y0,x);plot(x,y,-r)hold onplot(x,y1,-b)l10和fx在一起:x=-1:0.05:1;y=1./(1+25*x.2);x0=-1:0.2:1;y0=1./(1+25*x0.2);y2= lagrange(x0,y0,x);plot(x,y,-r)hold onplot(x,y2,-b)l20和fx在一起:x=-1:0.05:1;y=1./(1+25*x.2);x0=-1:0.1:1;y0=1./(1+25*x0.2);y3= lagrange(x0,y0,x);plot(x,y,-r)hold onplot(x,y3,-b)专心-专注-专业