數(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è),還剩18頁(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ù)考慮區(qū)間-1,1的一個(gè)等距劃分,節(jié)點(diǎn)為則拉格朗日插值多項(xiàng)式為其中的ai(x),i=0,1,2,n是n次Lagrange插值基函數(shù)。二、 實(shí)驗(yàn)內(nèi)容研究以下三個(gè)函數(shù)在各自區(qū)間上運(yùn)用不同的劃分1、2、3、運(yùn)用在區(qū)間-p,p上等距

2、劃分(p>0),節(jié)點(diǎn)為以x0,x1,xn為插值節(jié)點(diǎn)構(gòu)造上述各函數(shù)的Lagrange插值多項(xiàng)式。運(yùn)用區(qū)間a,b上切比雪夫(Chebychev)點(diǎn)的定義為以x1,x2,xn+1為插值節(jié)點(diǎn)構(gòu)造上述各函數(shù)的Lagrange插值多項(xiàng)式,比較其結(jié)果。并分別比較兩種劃分方法,增加節(jié)點(diǎn)數(shù),最大誤差的變化。三、 實(shí)驗(yàn)結(jié)果及分析(一) 等距劃分對(duì)于函數(shù)來(lái)說,使用等距劃分其中綠色點(diǎn)線代表誤差,紅色劃線代表Lagrange插值多項(xiàng)式,藍(lán)色實(shí)線代表原函數(shù)。可見對(duì)于等距劃分來(lái)說節(jié)點(diǎn)數(shù)越多,最大誤差越大,可是越靠近中間的誤差越少。越接近兩個(gè)端點(diǎn)的誤差越大。當(dāng)節(jié)點(diǎn)數(shù)很大時(shí),最大誤差的來(lái)源只與靠近兩個(gè)端點(diǎn)的誤差有關(guān)。例如

3、:n=20時(shí)對(duì)于,使用等距劃分當(dāng)n=25時(shí)對(duì)于,使用等距劃分當(dāng)n=30時(shí),從以上三個(gè)函數(shù)圖像來(lái)看,可見節(jié)點(diǎn)越多,靠近端點(diǎn)處取得最大誤差,并且最大誤差越大。這就是龍格現(xiàn)象。(二) 切比雪夫(Chebychev)點(diǎn)首先研究 當(dāng)n=20時(shí)可是當(dāng)n=30同樣的n=40,50也出現(xiàn)了兩端誤差增大現(xiàn)象。 然后研究 當(dāng)n=25時(shí)同樣的n=30,50也會(huì)出現(xiàn)龍格現(xiàn)象。最后研究當(dāng)n=25時(shí) 此函數(shù)也不例外。由以上三個(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或

4、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取的較小,同樣誤差也是很大的。對(duì)于以上兩種取節(jié)點(diǎn)的方法,都不能避免龍格現(xiàn)象的出現(xiàn)。對(duì)于不同的選取節(jié)點(diǎn)的方法,只要n取得合適,同時(shí)代人函數(shù)的點(diǎn)適合,那么就可以使誤差盡可能的減少。四、 關(guān)于本設(shè)計(jì)的體會(huì)為了完成本設(shè)計(jì),接觸了一個(gè)數(shù)學(xué)軟件matlab,并能初步運(yùn)用本

5、軟件,編寫程序,方便了以后對(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不熟悉,并不能更好的完善下去。有時(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ì)。五、

6、 參考文獻(xiàn)數(shù)值分析(第三版)北京理工大學(xué)出版社六、 附錄所的運(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)% 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

7、 KCSJX or the handle to% the existing singleton*.% KCSJX('CALLBACK',hObject,eventData,handles,.) calls the local% function named CALLBACK in KCSJX.M with the given input arguments.% KCSJX('Property','Value',.) creates a new KCSJX or raises the% existing singleton*. Starting f

8、rom the left, property value pairs are% applied to the GUI before kcsjx_OpeningFunction gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to kcsjx_OpeningFcn via varargin.% *See GUI Options on GUIDE's Tools menu. Choose "GUI

9、 allows only one% instance to run (singleton)".% See also: GUIDE, GUIDATA, GUIHANDLES% Copyright 2002-2003 The MathWorks, Inc.% Edit the above text to modify the response to help kcsjx% Last Modified by GUIDE v2.5 04-Jun-2012 16:03:46% Begin initialization code - DO NOT EDITgui_Singleton = 1;gu

10、i_State = struct('gui_Name', mfilename, . 'gui_Singleton', gui_Singleton, . 'gui_OpeningFcn', kcsjx_OpeningFcn, . 'gui_OutputFcn', kcsjx_OutputFcn, . 'gui_LayoutFcn', , . 'gui_Callback', );if nargin && ischar(varargin1) gui_State.gui_Callback =

11、 str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before kcsjx is made visible.function kcsjx_OpeningFcn(hObject, eventdata, handles, varargin)% This function ha

12、s no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to kcsjx (see VARARGIN)% Choose default command line output for kcsjxhandles.outpu

13、t = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes kcsjx wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = kcsjx_OutputFcn(hObject, eventdata, handles) % varargout cell array

14、 for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout1 = handles.output;function edit1_Callba

15、ck(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'Strin

16、g') returns contents of edit1 as a doubleinput = str2num(get(hObject,'String');if (isempty(input) set(hObject,'String','0')endguidata(hObject, handles); % - Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)

17、% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundCol

18、or','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');endfunction edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with h

19、andles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String') returns contents of edit2 as a doubleinput = str2num(get(hObject,'String'); if (isempty(input) set(hObject,'String','0') endgui

20、data(hObject, handles); % - Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all C

21、reateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');endfunction edit3_Callback(hObject, even

22、tdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text% str2double(get(hObject,'String') returns

23、contents of edit3 as a doubleinput = str2num(get(hObject,'String'); if (isempty(input) set(hObject,'String','0') endguidata(hObject, handles); % - Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject hand

24、le to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','w

25、hite');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor');end% - Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1 (see GCBO)% eventdata reserved - to be defined in a future v

26、ersion of MATLAB% handles structure with handles and user data (see GUIDATA)tic;v=get(handles.edit1,'String');t=get(handles.edit2,'String');n=get(handles.edit3,'String');kcsj(str2num(t),str2num(v),str2num(n);toc;clear;% - Executes on button press in pushbutton2.function pushb

27、utton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)tic;v=get(handles.edit1,'String');t=get(handles.edit2,'String');kcsj(str

28、2num(t),str2num(v);toc;clear;以下為主要程序。并且可以直接在命令框調(diào)用例如:在命令框輸入>> kcsj(1,1,3) %代表選擇等距劃分,選擇f(x)=1/(1+25*x2)輸出結(jié)果為:以下有具體說明。主程序文件名:kcsj.mfunction kcsj(t,v,n)%t為對(duì)不同x選擇的判斷,t=0時(shí)為等距劃分,t=1時(shí)為Chebychev劃分%v=1是選擇f(x)=1/(1+25*x2);v=2是f(x)=x/(1+x4);v=3是f(x)=atan(x)% 函數(shù)的選取%if v=1 %題目要求不同函數(shù),x有不同的取值范圍 p=1; %x取值范圍為-1

29、,1 f='1/(1+25*x2)'else if v=2 p=5; %x取值范圍為-5,5 f='x/(1+x4)' else if v=3 p=5; f='atan(x)' end endendif t=0 P='等距劃分'else P='Chebychev'endF=inline(f); %inline為將用字符串表示的函數(shù)表達(dá)式化為函數(shù)表達(dá)式%以下為不輸入n值得情況%if nargin=2 for 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=zer

30、os(n+1,1); %對(duì)應(yīng)有n+1個(gè)插值% 選擇節(jié)點(diǎn)選取方式 % if t=0 for 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劃分 end end% 計(jì)算差值 % for i=0:n Y(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=

31、9;-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); %subplot用于在同一窗口什么位置顯示圖像 fplot(f,-p,p,'c.-'); %畫出原函數(shù) if (n+1)/3)=2

32、 %添加適當(dāng)?shù)臉?biāo)題 title(f,P); end 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 off end%以下為輸入n值得情況%else if nargin=3 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

33、=0 for 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劃分 end end% 計(jì)算差值 % for i=0:n Y(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ù)最小值 maxe=abs(maxe); %得出最大誤差% 畫出函數(shù)圖像 % figure(v+t*3); %圖像窗口的編號(hào) subplot(1,1,1); fplot(

溫馨提示

  • 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)論