您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 三次样条插值函数逼近车门曲线
三次样条插值函数逼近车门曲线。插值节点数据:x012345678910y2.513.304.044.705.225.545.785.405.575.705.80y′0.80.2要求1)写出程序清单,生成M文件2)画出车门曲线图,给出插值结果,生成DOC文件。1、213221213121323121221212131231))()(2())()(2()()())(())(()](2[)()](2[)()(xxhyhmxxhmhyxhhyxhhyxxhmxxhmxhxhyxhxhykkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkxxxxxxxxxxxxxxxSfunctionyi=cubic_spline2(x,y,ydot,xi)%三次样条插值公式(三弯矩方程,第一类边界条件)%x为向量,全部的插值节点;%y为向量,插值节点处的函数值;%ydot为向量,端点处的导数值;若缺省,则用均差代替导数;%xi为标量,自变量x;%yi为xi处的函数估计值。n=length(x);ny=length(y);%输入的插值点与它的函数值应有相同的个数ifn~=nyerror('ThelengthsofXandYmustbeequal');return;end%如果没有给出端点处的导数值,则用均差代替导数ifisempty(ydot)==1ydot=[(y(2)-y(1))/(x(2)-x(1))(y(n)-y(n-1))/(x(n)-x(n-1))];endh=zeros(1,n);lambda=ones(1,n);mu=ones(1,n);m=zeros(n,1);d=zeros(n,1);fork=2:nh(k)=x(k)-x(k-1);%插入节点必须互异ifabs(h(k))epserror('theDATAiserror!');return;endendfork=2:n-1lambda(k)=h(k+1)/(h(k)+h(k+1));mu(k)=1-lambda(k);d(k)=3*(mu(k)*(y(k+1)-y(k))/h(k+1)+lambda(k)*(y(k)-y(k-1))/h(k));endd(2)=d(2)-lambda(2)*ydot(1);d(n-1)=d(n-1)-mu(n-1)*ydot(2);d(n)=[];d(1)=[];lambda(n)=[];lambda(1)=[];mu(n)=[];mu(1)=[];A=diag(2*ones(1,n-2));fori=1:n-3A(i,i+1)=mu(i);A(i+1,i)=lambda(i+1);endm=A\d;m=[ydot(1);m;ydot(2)];fork=2:nifx(k-1)=xi&&xi=x(k)yi=y(k-1)/h(k)^3*(xi-x(k))^2*(h(k)+2*(xi-x(k-1)))+y(k)/h(k)^3*(xi-x(k-1))^2*(h(k)+2*(x(k)-xi))+m(k-1)/h(k)^2*(xi-x(k-1))*(xi-x(k))^2+m(k)/h(k)^2*(xi-x(k))*(xi-x(k-1))^2;return;endend函数调用:x=[012345678910];y=[2.513.304.044.705.225.545.785.405.575.705.80];ydot=[0.80.2];xx=0.0:0.01:10.0;yy=cubic_spline2(x,y,ydot,xx);plot(x,y,'o',xx,yy,'r')%求插值函数系数:fork=2:na(k-1)=y(k-1)/h(k)^3;b(k-1)=y(k)/h(k)^3;c(k-1)=2*(y(k-1)/h(k)^3)+m(k-1)/h(k)^2;e(k-1)=m(k)/h(k)^2-2*(y(k)/h(k)^3);end结果显示:0123456789102.533.544.555.56各区间的插值函数:区间三次样条差值10x22221)1(8285.5)1(82.530.3)1(51.2)(xxxxxxxS21x22222)1)(2(3759.7)1()2(3715.7)1(04.4)2(30.3)(xxxxxxxS32x22223)2)(3(7877.8)2()3(7841.8)2(70.4)3(04.4)(xxxxxxxS43x22224)3)(4(0532.10)3()4(0123.10)3(22.5)4(70.4)(xxxxxxxS54x22225)4)(5(7194.10)4()5(8268.10)4(54.5)5(22.5)(xxxxxxxS65x22226)5)(6(7091.11)5()6(4406.11)5(78.5)6(54.5)(xxxxxxxS76x22227)6)(7(9844.10)6()7(4109.11)6(40.5)7(78.5)(xxxxxxxS87x22228)7)(8(8835.10)7()8(6156.10)7(57.5)8(40.5)(xxxxxxxS98x22229)8)(9(3416.11)8()9(3965.11)8(70.5)9(57.5)(xxxxxxxS109x222210)9)(10(4000.11)9()10(4584.11)9(80.5)10(70.5)(xxxxxxxS
本文标题:三次样条插值函数逼近车门曲线
链接地址:https://www.777doc.com/doc-6236455 .html