实习:Matlab作业hermite插值

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

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

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

资源描述

题目:利用Matlab实现数据的Hermite插值和分段三次Hermite插值小组成员:王晓波(3008210138)蔡明宇(3008210120)一、程序实现意义:一般的,从各种试验得来的数据总有一定的数量,而利用插值技术能够从有限的数据中获取整体的状态。而Hermite插值不仅保证了插值函数与原函数在给定数据点处得拟合,同时保证了在相应点处导数的相同,从而在很大程度上保证了曲线的“光滑性”。因此,通过Matlab实现Hermite插值具有很普遍的意义。二、实现过程:1、Hermite插值由于并不是所有的Matlab版本都提供现有的Hermite插值函数包,故我们首先编写了实现给定五个观测点的Hermite插值的M程序,代码如下:function[f,f0]=Hermite1(x,y,y_1)symst;f=0.0;if(length(x)==length(y))if(length(y)==length(y_1))n=length(x);elsedisp('y和y的导数的维数不相等');return;endelsedisp('x和y的维数不相等!');return;endfori=1:nh=1.0;a=0.0;forj=1:nif(j~=i)h=h*(t-x(j))^2/((x(i)-x(j))^2);a=a+1/(x(i)-x(j));endendf=f+h*((x(i)-t)*(2*a*y(i)-y_1(i))+y(i));endf0=subs(f,'t');其中x为给定点横坐标数组,y为给定点纵坐标数组,y_1为原函数在给定点处的导数数组。测试证明该程序可以实现,例如输入如下数组:x=1:0.2:1.8;y_1=[0.50.45640.42260.39530.3727];y=[11.09541.18321.26491.3416];[f,f0]=Hermite1(x,y,y_1);运行结果如下:f=(390625*((337232823972231*t)/35184372088832-114418258618928321/10995116277760000)*(t-1)^2*(t-7/5)^2*(t-8/5)^2*(t-9/5)^2)/36-(390625*(t-1)^2*(t-6/5)^2*(t-7/5)^2*(t-9/5)^2*((2855713758717179*t)/281474976710656-384779664999124623/21990232555520000))/36+(390625*((64*t)/3-61/3)*(t-6/5)^2*(t-7/5)^2*(t-8/5)^2*(t-9/5)^2)/576+(390625*((7612884810106783*t)/18014398509481984+6660373488918492043/11258999068426240000)*(t-1)^2*(t-6/5)^2*(t-8/5)^2*(t-9/5)^2)/16-(390625*((7762319875242775*t)/281474976710656-8968626627620006931/175921860444160000)*(t-1)^2*(t-6/5)^2*(t-7/5)^2*(t-8/5)^2)/576f0=1.1000.利用matlab绘制图像:2、程序的窗口化:利用Matlab提供的GUIDE工具以及callback函数实现相应函数的窗口化,GUI代码如下:functionvarargout=untitled(varargin)%UNTITLEDM-fileforuntitled.fig%UNTITLED,byitself,createsanewUNTITLEDorraisestheexisting%singleton*.%%H=UNTITLEDreturnsthehandletoanewUNTITLEDorthehandleto%theexistingsingleton*.%%UNTITLED('CALLBACK',hObject,eventData,handles,...)callsthelocal%functionnamedCALLBACKinUNTITLED.Mwiththegiveninputarguments.%%UNTITLED('Property','Value',...)createsanewUNTITLEDorraisesthe%existingsingleton*.Startingfromtheleft,propertyvaluepairsare%appliedtotheGUIbeforeuntitled_OpeningFcngetscalled.An%unrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.Allinputsarepassedtountitled_OpeningFcnviavarargin.%%*SeeGUIOptionsonGUIDE'sToolsmenu.ChooseGUIallowsonlyone%instancetorun(singleton).%%Seealso:GUIDE,GUIDATA,GUIHANDLES%Edittheabovetexttomodifytheresponsetohelpuntitled%LastModifiedbyGUIDEv2.515-Sep-201122:24:48%Begininitializationcode-DONOTEDITgui_Singleton=1;gui_State=struct('gui_Name',mfilename,...'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@untitled_OpeningFcn,...'gui_OutputFcn',@untitled_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);ifnargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});endifnargout[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:});elsegui_mainfcn(gui_State,varargin{:});end%Endinitializationcode-DONOTEDIT%---Executesjustbeforeuntitledismadevisible.functionuntitled_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstountitled(seeVARARGIN)%Choosedefaultcommandlineoutputforuntitledhandles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesuntitledwaitforuserresponse(seeUIRESUME)%uiwait(handles.figure1);%---Outputsfromthisfunctionarereturnedtothecommandline.functionvarargout=untitled_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;functionedit1_Callback(hObject,eventdata,handles)%hObjecthandletoedit1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofedit1astext%str2double(get(hObject,'String'))returnscontentsofedit1asadoubleguidata(hObject,handles);%---Executesduringobjectcreation,aftersettingallproperties.functionedit1_CreateFcn(hObject,eventdata,handles)%hObjecthandletoedit1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionedit2_Callback(hObject,eventdata,handles)%hObjecthandletoedit2(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofedit2astext%str2double(get(hObject,'String'))returnscontentsofedit2asadoubleguidata(hObject,handles);%---Executesduringobjectcreation,aftersettingallproperties.functionedit2_CreateFcn(hObject,eventdata,handles)%hObjecthandletoedit2(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%hand

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

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

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

×
保存成功