實習:Matlab作業(yè)hermite插值_第1頁
實習:Matlab作業(yè)hermite插值_第2頁
實習:Matlab作業(yè)hermite插值_第3頁
實習:Matlab作業(yè)hermite插值_第4頁
實習:Matlab作業(yè)hermite插值_第5頁
已閱讀5頁,還剩7頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

1、題目:利用插值實現(xiàn)數(shù)據(jù)的插值和分段三次小組成員:王曉波(1蔡明宇()一、程序?qū)崿F(xiàn)意義:一般的,從各種試驗得來的數(shù)據(jù)總有一定的數(shù)量,而利用插值技術能夠從有限的數(shù)據(jù)中獲取整體的狀態(tài)。而Hermite插值不僅保證了插值函數(shù)與原函數(shù)在給定數(shù)據(jù)點處得擬合,同時保證了在相應點處導數(shù)的相同,從而在很大程度上保證了曲線的“光滑性”。因此,通過Matlab實現(xiàn)Hermite插值具有很普遍的意義。二、實現(xiàn)過程:1、Hermite插值由于并不是所有的Matlab版本都提供現(xiàn)有的Hermite插值函數(shù)包,故我們首先編寫了實現(xiàn)給定五個觀測點的Hermite插值的M程序,代碼如下:functionf,f0=Hermite

2、1(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的導數(shù)的維數(shù)不相等);return;endelsedisp(x和y的維數(shù)不相等!);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);其中為給定點橫坐標數(shù)組,為給定點縱

3、坐標數(shù)組,為原函數(shù)在給定點處的導數(shù)數(shù)組。測試證明該程序可以實現(xiàn),例如輸入如下數(shù)組: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);運行結(jié)果如下:f=TOC o 1-5 h z(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)A2*(t-

4、6/5)A2*(t-7/5)A2*(t-9/5)A2*(2855713758717179*t)/281474976710656-384779664999124623/21990232555520000)/36+(390625*(64*t)/3-61/3)*(t-6/5)A2*(t-7/5)A2*(t-8/5)A2*(t-9/5)A2)/576+(390625*(7612884810106783*t)/18014398509481984+6660373488918492043/11258999068426240000)*(t-1)A2*(t-6/5)A2*(t-8/5)A2*(t-9/5)A2)

5、/16-(390625*(7762319875242775*t)/281474976710656-8968626627620006931/175921860444160000)*(t-1)A2*(t-6/5)A2*(t-7/5)A2*(t-8/5)A2)/576f0=1.1000利用matlab繪制圖像:FigureFileEditViewInsertToolsDtEktopWindowHelpH3口匡1口1.41.351.32、程序的窗口化:利用Matlab:GUI代碼如下:1.25提供的GUIDE工具以及callback函數(shù)實現(xiàn)相應函數(shù)的窗口化,/functionvararg?utUNTI

6、TLEDM-fileUNTITLED,bysingleton*.=untitled(varargin)”foruntitled.fig/itself,createsanewUNTITLEDorraisestheexistingH=UNTITLED_*returnsthehandleanewUNTITLEDorthehandletotheexisting1.05singleton*.UNTITLED(CALLBACK,local,hObject,eventData,handles,.)callsthe1.41111functionnamedCALLBACKi1n1UNTITLED.MWithth

7、egivenTinputarguments.%UNTITLED(Property,Valuecreatesanewun丄丄丄ledorraisestheexistingsingleton*.Startingfromtheleft,propertyvaluepairsareappliedtotheGUIbeforeuntitled_OpeningFcngetscalled.Anunrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.Allinputsarepassedtountitled_OpeningFcnviav

8、arargin.%*SeeGUIOptionsonGUIDEsToolsmenu.ChooseGUIallowsonlyoneinstancetorun(singleton)%Seealso:GUIDE,GUIDATA,GUIHANDLES%Edittheabovetexttomodifytheresponsetohelpuntitled%LastModifiedbyGUIDEv2.515-Sep-201122:24:48ifnargoutBegininitializationcode-DOgui_Singleton=1;gui_StateNOTEDIT=struct(gui_Name,gui

9、_Singleton,gui_OpeningFcn,gui_OutputFcn,gui_LayoutFcn,gui_Callback,&ischar(varargin1)mfilename,.gui_Singleton,.untitled_OpeningFcn,.untitled_OutputFcn,.,.);ifnargingui_State.gui_Callback=str2func(varargin1);endvarargout1:nargout=gui_mainfcn(gui_State,varargin:);elsegui_mainfcn(gui_State,varargin:);e

10、nd%Endinitializationcode-DONOTEDIT%-Executesjustbeforeuntitledismadevisible.functionuntitled_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(see

11、GUIDATA)%varargincommandlineargumentstountitled(seeVARARGIN)%Choosedefaultcommandlineoutputforuntitledhandles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesuntitledwaitforuserresponse(seeUIRESUME)%uiwait(handles.figure1);%-Outputsfromthisfunctionarereturnedtothecommandli

12、ne.functionvarargout=untitled_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevar

13、argout1=handles.output;functionedit1_Callback(hObject,eventdata,handles)%hObjecthandletoedit1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,String)returnscontentsofedit1astext%str2double(get(hObject,String)returnsc

14、ontentsofedit1asadoubleguidata(hObject,handles);%-Executesduringobjectcreation,aftersettingallproperties.functionedit1_CreateFcn(hObject,eventdata,handles)%hObjecthandletoedit1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%

15、Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundColor)set(hObject,BackgroundColor,white);endfunctionedit2_Callback(hObject,eventdata,handles)%hObjecthandletoedit2(seeGCBO)%eventdatareserved-tobedefi

16、nedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,String)returnscontentsofedit2astext%str2double(get(hObject,String)returnscontentsofedit2asadoubleguidata(hObject,handles);%-Executesduringobjectcreation,aftersettingallproperties.functionedit2_CreateFcn(

17、hObject,eventdata,handles)%hObjecthandletoedit2(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&isequal(get(hObject,BackgroundColor),get(0,defau

18、ltUicontrolBackgroundColor)set(hObject,BackgroundColor,white);endfunctionedit3_Callback(hObject,eventdata,handles)%hObjecthandletoedit3(seeGCBO)%eventdatareservedtobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,String)returnscontentsofedit3aste

19、xt%str2double(get(hObject,String)returnscontentsofedit3asadoubleguidata(hObject,handles);%-Executesduringobjectcreation,aftersettingallproperties.functionedit3_CreateFcn(hObject,eventdata,handles)%hObjecthandletoedit3(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handle

20、snotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundColor)set(hObject,BackgroundColor,white);endfunctionedit4_Callback(hObject,eventdata,handles)%hObjecthandleto

21、edit4(seeGCBO)%eventdatareservedtobedefinedinafutureversionofMATLAB%eventdatareservedtobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,String)returnscontentsofedit4astext%str2double(get(hObject,

22、String)returnscontentsofedit4asadouble%-Executesduringobjectcreation,aftersettingallproperties.functionedit4_CreateFcn(hObject,eventdata,handles)%hObjecthandletoedit4(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editc

23、ontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&isequal(get(hObject,BackgroundColor),get(0,defaultUicontrolBackgroundColor)set(hObject,BackgroundColor,white);end%-Executesonbuttonpressinpushbutton1.functionpushbutton1_Callback(hObject,eventdata,handles)%hObjecthandletopushbutt

24、on1(seeGCBO)x=str2num(get(handles.edit1,string);y=str2num(get(handles.edit2,string);y_1=str2num(get(handles.edit3,string);x0=str2num(get(handles.edit5,string);symst;f=0.0;if(length(x)=length(y)if(length(y)=length(y_1)n=length(x);elsedisp(yfyp亙卩吻總亙(總?2工卩總);return;endelsedisp(xfy卩亙f總卩總:);return;endfor

25、i=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,x0);plot(handles.poltarea,x,y,*);functionedit5_Callback(hObject,eventdata,handles)%hObjecthandletoedit5(seeGCBO)%eventdatareservedtobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,String)returnscontentsofedit5astext%str2double(get(hObject,String)returnscontentsofedit

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論