matlab---三次样条插值

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

4444多项式插值与函数最佳逼近多项式插值与函数最佳逼近多项式插值与函数最佳逼近多项式插值与函数最佳逼近37373737(上机题)3333次样条插值函数:(1)编制求第一型3次样条插值函数的通用程序;(2)已知汽车门曲线型值点的数据如下:i012345xi012345yi2.513.304.044.705.225.54i678910xi678910yi5.785.405.575.705.80端点条件为8.0'0=y,2.0'10=y,用所编程序求车门的3次样条插值函数S(x),并打印出9,,1,0),5.0(⋯=+iiS。用matlab编写通用程序为:function[Sx]=Threch(X,Y,dy0,dyn)%X为输入变量x的数值%Y为函数值y的数值%dy0为左端一阶导数值%dyn为右端一阶导数值%Sx为输出的函数表达式n=length(X)-1;d=zeros(n+1,1);h=zeros(1,n-1);f1=zeros(1,n-1);f2=zeros(1,n-2);fori=1:n%求函数的一阶差商h(i)=X(i+1)-X(i);f1(i)=(Y(i+1)-Y(i))/h(i);endfori=2:n%求函数的二阶差商f2(i)=(f1(i)-f1(i-1))/(X(i+1)-X(i-1));d(i)=6*f2(i);endd(1)=6*(f1(1)-dy0)/h(1);d(n+1)=6*(dyn-f1(n-1))/h(n-1);%赋初值A=zeros(n+1,n+1);B=zeros(1,n-1);C=zeros(1,n-1);fori=1:n-1B(i)=h(i)/(h(i)+h(i+1));C(i)=1-B(i);endA(1,2)=1;A(n+1,n)=1;fori=1:n+1A(i,i)=2;endfori=2;nA(i,i-1)=B(i-1);A(i,i+1)=C(i-1);endM=A\d;symsx;fori=1:nSx(i)=collect(Y(i)+(f1(i)-(M(i)/3+M(i+1)/6)*h(i))*(x-X(i))...+M(i)/2*(x-X(i))^2+(M(i+1)-M(i))/(6*h(i))*(x-X(i))^3);digits(4);Sx(i)=vpa(Sx(i));endfori=1:ndisp('S(x)=');fprintf('%s(%d,%d)\n',char(Sx(i)),X(i),X(i+1));endS=zeros(1,n);fori=1:nx=X(i)+0.5;S(i)=Y(i)+(f1(i)-(M(i)/3+M(i+1)/6)*h(i))*(x-X(i))...+M(i)/2*(x-X(i))^2+(M(i+1)-M(i))/(6*h(i))*(x-X(i))^3;enddisp('S(i+0.5)');disp('iX(i+0.5)S(i+0.5)');fori=1:nfprintf('%d%.4f%.4f\n',i,X(i)+0.5,S(i));endEnd在运行窗口输入:X=[012345678910];Y=[2.513.304.044.705.225.545.785.405.575.705.80];Threch(X,Y,0.8,0.2)运行结果如下:S(x)=-0.005714*x^3-0.004286*x^2+0.8*x+2.51(0,1)S(x)=-0.01286*x^3+0.01714*x^2+0.7786*x+2.517(1,2)S(x)=-0.015*x^3+0.03*x^2+0.795*x+2.45(2,3)S(x)=-0.015*x^3+0.03*x^2+0.865*x+2.24(3,4)S(x)=0.03*x^3-0.51*x^2+3.08*x-0.86(4,5)S(x)=-0.135*x^3+1.965*x^2-9.09*x+18.74(5,6)S(x)=0.2925*x^3-5.73*x^2+36.96*x-72.9(6,7)S(x)=-0.1475*x^3+3.51*x^2-27.55*x+76.87(7,8)S(x)=0.0025*x^3-0.09*x^2+1.118*x+1.11(8,9)S(x)=0.04625*x^3-1.271*x^2+11.72*x-30.53(9,10)S(i+0.5)iX(i+0.5)S(i+0.5)10.50002.908221.50003.680232.50004.390643.50004.991954.50005.406365.50005.725676.50005.596687.50005.437298.50005.6416109.50005.7383

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功