數(shù)值分析課程設(shè)計(jì)-多項(xiàng)式插值的振蕩現(xiàn)象matlab_第1頁(yè)
數(shù)值分析課程設(shè)計(jì)-多項(xiàng)式插值的振蕩現(xiàn)象matlab_第2頁(yè)
數(shù)值分析課程設(shè)計(jì)-多項(xiàng)式插值的振蕩現(xiàn)象matlab_第3頁(yè)
數(shù)值分析課程設(shè)計(jì)-多項(xiàng)式插值的振蕩現(xiàn)象matlab_第4頁(yè)
數(shù)值分析課程設(shè)計(jì)-多項(xiàng)式插值的振蕩現(xiàn)象matlab_第5頁(yè)
已閱讀5頁(yè),還剩40頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、數(shù)值分析課程設(shè)計(jì)多項(xiàng)式插值的振蕩現(xiàn)象(姓名)(學(xué)號(hào))指導(dǎo)教師 一學(xué)院名稱專業(yè)名稱提交日期 2012年6月一、問題的提出考慮在一個(gè)固定區(qū)間上用插值逼近一個(gè)函數(shù)。顯然, Lagrange插值中使用的節(jié)點(diǎn)越多,插值多項(xiàng)式的次數(shù)就越高。我們自然關(guān)心插值多項(xiàng)式增加時(shí),Ln(x)是否也更加靠近被逼近的函數(shù)。龍格(Runge)給出的一個(gè)例子是極著名并 富有啟發(fā)性的。設(shè)區(qū)間-1,1上的函數(shù)f(x)11 25x2-可編輯修改-考慮區(qū)間-1,1的一個(gè)等距劃分,節(jié)點(diǎn)為則拉格朗日插值多項(xiàng)式為L(zhǎng)n(x)2i ni 0,1,2,L ,n125xi2A(x)其中的ai(x),i=0,1,2,n是n次Lagrange 插值基

2、函數(shù)。二、實(shí)驗(yàn)內(nèi)容研究以下三個(gè)函數(shù)在各自區(qū)間上運(yùn)用不同的劃分/.11、 f(x) ,x 1,11 25x一x2、h(x) 4,x 5,51 x3、g (x) arctan x, x 5,5運(yùn)用在區(qū)間卜p,p上等距劃分(p>0 ),節(jié)點(diǎn)為x p 2i, i 0,1,2,L ,nn以xo,xi,,xn為插值節(jié)點(diǎn)構(gòu)造上述各函數(shù)的Lagrange插值多項(xiàng)式。運(yùn)用區(qū)間a,b上切比雪夫(Chebychev)點(diǎn)的定義為xkbaba (2k 1)cos, k 1,2,L ,n 12 22(n 1)以xi,X2,,xn+1為插值節(jié)點(diǎn)構(gòu)造上述各函數(shù)的Lagrange插值多項(xiàng)式,比較其結(jié)并分別比較兩種劃分方法

3、,增加節(jié)點(diǎn)數(shù),最大誤差的變化三、實(shí)驗(yàn)結(jié)果及分析(一)等距劃分1對(duì)于函數(shù)f(x) T,x 1,1來(lái)說,使用等距劃分 1 25x選擇函數(shù) I 11. f(x)=1/(1+25*xA2) (-1,1)2、f(x)=x/(1+xM)G5.5)3、f(x)=atan(x)(-5:5)選擇不同的節(jié)點(diǎn)劃分方式|;0、等距劃分1、Chebychev劃分顯示多個(gè)不同n值的圖像:顯示輸入n的值顯示此圖像運(yùn)行其中綠色點(diǎn)線代表誤差,紅色劃線代表Lagrange插值多項(xiàng)式,藍(lán)色實(shí)線代表原函數(shù)。越少。越接近兩個(gè)端點(diǎn)的誤差越大。當(dāng)節(jié)點(diǎn)數(shù)很大時(shí),最大誤差的來(lái)源只與靠近 兩個(gè)端點(diǎn)的誤差有關(guān)。例如:n=20時(shí)選擇函數(shù) I 11,

4、 f(x)=1/(1+25*XA2) (-1,1)2, f(x)=x/(1+xA4) (巨5)3, f(x)=atan(x) (-5,5)選擇不同的節(jié)點(diǎn)劃分方式|;0、等距劃分1、Chebycheu劃分顯示多個(gè)不同n值的圖像|輸入n的值k 顯示此圖像x對(duì)于h(x) 4,x 5,5,使用等距劃分1 x選擇函數(shù) I ;'1. f(x)=1/(1+25V2) G1J)2、f(x)=x/(1+xA4)(-5,5)3、f(x)=atan(x)(-5,5)選擇不同的節(jié)點(diǎn)劃分方式|;0、等距劃分1、Chebychev劃分顯示多個(gè)不同n值的圖像匚礪輸入n的值=顯示此圖像 運(yùn)行105 00.6nW最大誤

5、差二0 66837 n二8最大誤差二0 3Z474n二2最大誤 ft =0 56866當(dāng)n=25時(shí)對(duì)于g(x) arctan x,x 5,5,使用等距劃分選擇函數(shù)31、f(x)=1/(1+25*XA2) (-1,1)2、f(x)=x/(1+xA4)(-5,5)3、f(x)=atan(x)(-5,5)選擇不同的節(jié)點(diǎn)劃分方式|;0、等距劃分1、Chebychev劃分顯示多個(gè)不同n值的圖像顯示輸入n的值h顯示此圖像匚運(yùn)行:般n(x)等距劃分當(dāng)n=30時(shí),從以上三個(gè)函數(shù)圖像來(lái)看,可見節(jié)點(diǎn)越多,靠近端點(diǎn)處取得最大誤差,并且o最大誤差越大。這就是龍格現(xiàn)象。(二)切比雪夫(Chebychev)點(diǎn)1首先研究

6、f(x) 2,x 1,11 25x2選擇函數(shù)'K f(x)=1/(1+25V2) (-1,1)2、f(x)=x/(1+xM)(-5,5)3、f(x)=atan(x)(-5,5)選擇不同的節(jié)點(diǎn)劃分方式|;0、等距劃分1. Chebychev劃分顯示多個(gè)不同n值的圖像 顯示|輸入n的值口廠顯示此圖像匚行二|當(dāng)n=20時(shí)可是當(dāng)n=30同樣的n=40 , 50也出現(xiàn)了兩端誤差增大現(xiàn)象x然后研究h(x) 4 ,x 5,51 x選擇函數(shù)21、f(x)=1/(1+25*xA2) (-1,1)2、f(x)=x/(1+xA4)(-5,5)3、f(x)= at己n(x)(-5,5)選擇不同的節(jié)點(diǎn)劃分方式|

7、;0、等距劃分1、Chebychev劃分顯示多個(gè)不同n值的圖像匚北示口輸入n的值k顯示此圖像 運(yùn)行Ix/i 1+x JChebychev當(dāng)n=25時(shí)25最大誤差最7_ 1206同樣的n=30 , 50也會(huì)出現(xiàn)龍格現(xiàn)象最后研究 g(x) arctan x, x 5,5選擇函數(shù)I 31、f(x>1/(1 + 25+xA2) (-1,1)2、f(x)=x/(1+xA4)(-5,5)3、f(x)=atari(x)(-5,5)選擇不同的節(jié)點(diǎn)劃分方式10、等距劃分1、Chebychev劃分顯示多個(gè)不同n值的圖像匚顯示二|輸入n的值E顯示此圖像 運(yùn)行Iatan(x)Ghebychev當(dāng)n=25時(shí)此函數(shù)

8、也不例外。由以上三個(gè)函數(shù),通過不斷改變n 的值,可得運(yùn)用切比雪夫點(diǎn)來(lái)劃分,要使最大誤差小于0.1 , n 一般取 12 到 20 間的數(shù)。(三) 綜述對(duì)于 Lagrange 插值多項(xiàng)式,運(yùn)用等距劃分取節(jié)點(diǎn)時(shí),n 要不能取得太大,一般n=8 或 8 左右。若要使n 取得更大,那么需要使代入到函數(shù)的點(diǎn)盡量在區(qū)間的中間,這樣才能使真值與計(jì)算出來(lái)的值的誤差盡可能的小。運(yùn)用切比雪夫點(diǎn)來(lái)劃分取節(jié)點(diǎn)時(shí),n 一般取 12 到 20 間的數(shù)。無(wú)論要代入到函數(shù)的點(diǎn)在區(qū)間的那個(gè)位置,都能使誤差盡可能的小。若要使n 取得更大,那么需要使代入到函數(shù)的點(diǎn)盡量在區(qū)間的中間,這樣才能使真值與計(jì)算出來(lái)的值的誤差盡可能的小。若n

9、 取的較小,同樣誤差也是很大的。對(duì)于以上兩種取節(jié)點(diǎn)的方法,都不能避免龍格現(xiàn)象的出現(xiàn)。對(duì)于不同的選取節(jié)點(diǎn)的方法,只要n 取得合適,同時(shí)代人函數(shù)的點(diǎn)適合,那么就可以使誤差盡可能的減少。4、 關(guān)于本設(shè)計(jì)的體會(huì)為了完成本設(shè)計(jì),接觸了一個(gè)數(shù)學(xué)軟件matlab ,并能初步運(yùn)用本軟件,編寫程序,方便了以后對(duì)數(shù)學(xué)的研究。并且對(duì)于編寫過程中遇到的錯(cuò)誤,顯示不正確等,通過網(wǎng)絡(luò)搜索查詢,能解決這些問題。例如運(yùn)用fminbnd 函數(shù)時(shí),顯示的并不是正確的答案,后來(lái)百度了一下,明白了此函數(shù)的運(yùn)作原理,并最終能顯示我想得到的結(jié)果。當(dāng)然對(duì)于我所編寫的程序,我也就只能做到這一步,也是礙于時(shí)間關(guān)系,和對(duì) matlab 不熟悉,

10、并不能更好的完善下去。有時(shí)取值很大時(shí),運(yùn)行起來(lái),運(yùn)行得很慢, 這是一大缺陷。主要是循環(huán)次數(shù)太多,和找不到更好的函數(shù)代替所造成的。其他的缺點(diǎn)也就不的列舉了學(xué)習(xí)一個(gè)軟件需要耐心,細(xì)心。多尋找,多發(fā)現(xiàn),多創(chuàng)作才能深入了解一個(gè)軟件。同樣的道理,這也是做任何事所需要的素質(zhì)。5、 參考文獻(xiàn)數(shù)值分析(第三版)北京理工大學(xué)出版社6、 附錄所的運(yùn)用軟件及編號(hào)MATLAB 7.0(圖略)所用電腦的版本、型號(hào)與系統(tǒng)(圖略)用戶界面設(shè)計(jì)文件名:kcsjx.fig-可編輯修改-用戶界面程序,運(yùn)行kcsjx.m來(lái)調(diào)用主要程序文件名:kcsjx.mfunction varargout = kcsjx(varargin)%

11、KCSJX M-file for kcsjx.fig% KCSJX, by itself, creates a new KCSJX or raises the existing% singleton*.% H = KCSJX returns the handle to a new KCSJX or the handle to% the existing singleton*.KCSJX('CALLBACK',hObject,eventData,handles,.) calls the local% function named CALLBACK in KCSJX.M with

12、the given input arguments.%KCSJX('Property','Value',.) creates a new KCSJX or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before kcsjx_OpeningFunction gets called. An% unrecognized property name or invalid value makes property

13、 application% stop. All inputs are passed to kcsjx_OpeningFcn via varargin.% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".% See also: GUIDE, GUIDATA, GUIHANDLES% Copyright 2002-2003 The MathWorks, Inc.% Edit the above text to modify

14、the response to help kcsjx% Last Modified by GUIDE v2.5 04-Jun-2012 16:03:46% Begin initialization code - DO NOT EDIT gui_Singleton = 1;mfilename, .gui_State = struct('gui_Name','gui_Singleton', gui_Singleton, .'gui_OpeningFcn', kcsjx_OpeningFcn, .'gui_OutputFcn',kcsj

15、x_OutputFcn, .'gui_LayoutFcn', , .'gui_Callback',);if nargin && ischar(varargin1)gui_State.gui_Callback = str2func(varargin1);end if nargoutvarargout1:nargout = gui_mainfcn(gui_State, varargin:);elsegui_mainfcn(gui_State, varargin:);end % End initialization code - DO NOT EDIT

16、% - Executes just before kcsjx is made visible.function kcsjx_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdatareserved - to be defined in a future version of MATLAB% handlesstructure with handles and user data (s

17、ee GUIDATA)% varargin command line arguments to kcsjx (see VARARGIN)% Choose default command line output for kcsjxhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes kcsjx wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this fun

18、ction are returned to the command line.function varargout = kcsjx_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args (see VARARGOUT);% hObjecthandle to figure% eventdatareserved - to be defined in a future version of MATLAB% handlesstructure with handles and user

19、data (see GUIDATA)% Get default command line output from handles structure varargout1 = handles.output;function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdatareserved - to be defined in a future version of MATLAB% handlesstructure with handles and user dat

20、a (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text%str2double(get(hObject,'String') returns contents of edit1 as adoubleinput = str2num(get(hObject,'String');if (isempty(input)set(hObject,'String','0')end guidata(hObject, handles);

21、% - Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdatareserved - to be defined in a future version of MATLAB% handlesempty - handles not created until after all CreateFcnscalled% Hint: edi

22、t controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor') );endfunction edit2_Callback(hObject, eventdata, handles)% hObject ha

23、ndle to edit2 (see GCBO)% eventdatareserved - to be defined in a future version of MATLAB% handlesstructure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text%str2double(get(hObject,'String') returns contents of edit2 as adoublein

24、put = str2num(get(hObject,'String');if (isempty(input)set(hObject,'String','0')endguidata(hObject, handles);% - Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdatare

25、served - to be defined in a future version of MATLAB% handlesempty - handles not created until after all CreateFcnscalled% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'Backgro

26、undColor',get(0,'defaultUicontrolBackgroundColor') );end function edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdatareserved - to be defined in a future version of MATLAB% handlesstructure with handles and user data (see GUIDATA)% Hints: get(hObjec

27、t,'String') returns contents of edit3 as text%str2double(get(hObject,'String') returns contents of edit3 as adoubleinput = str2num(get(hObject,'String');if (isempty(input)set(hObject,'String','0')endguidata(hObject, handles);% - Executes during object creation

28、, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObjecthandle to edit3 (see GCBO)% eventdatareserved - to be defined in a future version of MATLAB% handlesempty - handles not created until after all CreateFcnscalled% Hint: edit controls usually have a white back

29、ground on Windows.% See ISPC and COMPUTER.if ispcset(hObject,'BackgroundColor','white');elseset(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor') );end% - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handle

30、s)% hObject handle to pushbutton1 (see GCBO)% eventdatareserved - to be defined in a future version of MATLAB% handlesstructure with handles and user data (see GUIDATA) tic;-可編輯修改-v=get(handles.edit1,'String');t=get(handles.edit2,'String');n=get(handles.edit3,'String');kcsj(s

31、tr2num(t),str2num(v),str2num(n);toc;clear;% - Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdatareserved - to be defined in a future version of MATLAB% handlesstructure with handles and user data (se

32、e GUIDATA)tic;v=get(handles.edit1,'String');t=get(handles.edit2,'String');kcsj(str2num(t),str2num(v);toc;clear;以下為主要程序。并且可以直接在命令框調(diào)用例如:在命令框輸入>> kcsj(1,1,3) % 代表選擇等距劃分,選擇 f(x)=1/(1+25*xA2)輸出結(jié)果為:以下有具體說明。主程序文件名:kcsj.mfunction kcsj(t,v,n)%t為對(duì)不同x選擇的判斷,t=0時(shí)為等距劃分,t=1時(shí)為Chebychev劃分%v=1 是

33、選擇 f(x)=1/(1+25*xA2);v=2是 f(x)=x/(1+xA4);v=3是f(x)=atan(x)%函數(shù)的選取%if v=1%題目要求不同函數(shù),x有不同的取值范圍p=1;%x取值范圍為-1,1f='1/(1+25*xA2)'else if v=2p=5; %x 取值范圍為-5,5f='x/(1+xA4)'else if v=3p=5;f='atan(x)'endendendif t=0P=' 等距劃分'elseP='Chebychev'endF=inline(f);%inline 為將用字符串表示的

34、函數(shù)表達(dá)式化為函數(shù)表達(dá)式% 以下為不輸入n 值得情況%if nargin=2for n=2:3:17%節(jié)點(diǎn)數(shù)由2 至 11 進(jìn)行循環(huán)操作X=zeros(n+1,1);%有n+1 個(gè)節(jié)點(diǎn)Y=zeros(n+1,1);%對(duì)應(yīng)有 n+1 個(gè)插值%選擇節(jié)點(diǎn)選取方式%if t=0for i=0:n-可編輯修改-%等距劃分X(i+1,1)=-p+2*p*i/n;end%else%for i=1:n+1%X(i,1)=p*cos(2*i-1)*pi/(2*(n+1);%Chebychev 劃分endend%計(jì)算差值%for i=0:nY(i+1,1)=F(X(i+1,1);end% 通過差值與節(jié)點(diǎn)得出Lag

35、range 公式%Pn=Lagrange3(X,Y);%調(diào)用拉格朗日函數(shù)進(jìn)行Ln=inline(Pn);% 計(jì)算原函數(shù)與Ln 兩個(gè)函數(shù)間的最大誤差%maxe='-abs(',char(Pn),'-',f,')'max=inline('abs(',char(Pn),'-',f,')');maxe=fmin(maxe,X);%調(diào)用fmin.m 查找函數(shù)最小值maxe=abs(maxe);%得出最大誤差%畫出函數(shù)圖像%figure(v+t*3);%圖像窗口的編號(hào)subplot(2,3,(n+1)/3);

36、%subplot 用于在同一窗口什么位置顯示圖像fplot(f,-p,p,'c.-');%畫出原函數(shù)if (n+1)/3)=2% 添加適當(dāng)?shù)臉?biāo)題endtitle(f,P);hold on%多個(gè)函數(shù)在同一個(gè)圖像表達(dá)fplot(Ln,-p,p);%畫出拉格朗日?qǐng)D像xlabel('n=',num2str(n),' 最大誤差=',num2str(maxe);%在x 軸標(biāo)注 n 節(jié)點(diǎn)的取值與最大誤差fplot(max,-p,p,'r:');%畫出誤差圖像hold offend% 以下為輸入n 值得情況 %else if nargin=3X=

37、zeros(n+1,1);%有n+1 個(gè)節(jié)點(diǎn)Y=zeros(n+1,1);%對(duì)應(yīng)有 n+1 個(gè)插值%選擇節(jié)點(diǎn)選取方式%if t=0for i=0:nX(i+1,1)=-p+2*p*i/n;%等距劃分endelse%for i=1:n+1%X(i,1)=p*cos(2*i-1)*pi/(2*(n+1);%Chebychev 劃分endend%計(jì)算差值%for i=0:nY(i+1,1)=F(X(i+1,1);end% 通過差值與節(jié)點(diǎn)得出Lagrange 公式%Pn=Lagrange3(X,Y); %調(diào)用拉格朗日函數(shù)進(jìn)行Ln=inline(Pn);% 計(jì)算原函數(shù)與Ln 兩個(gè)函數(shù)間的最大誤差%maxe='-abs(',char(Pn),'-',f,')'max=inline('abs(',char(Pn),'-',f,')');maxe=fmin(maxe,X);%調(diào)用fmin.m 查找函數(shù)最小

溫馨提示

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

評(píng)論

0/150

提交評(píng)論