数值分析课程设计-多项式插值的振荡现象matlab(共23页).doc

上传人:飞****2 文档编号:7091757 上传时间:2022-02-18 格式:DOC 页数:23 大小:525.50KB
返回 下载 相关 举报
数值分析课程设计-多项式插值的振荡现象matlab(共23页).doc_第1页
第1页 / 共23页
数值分析课程设计-多项式插值的振荡现象matlab(共23页).doc_第2页
第2页 / 共23页
点击查看更多>>
资源描述

《数值分析课程设计-多项式插值的振荡现象matlab(共23页).doc》由会员分享,可在线阅读,更多相关《数值分析课程设计-多项式插值的振荡现象matlab(共23页).doc(23页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上数值分析 课程设计多项式插值的振荡现象(姓名)(学号)指导教师 学院名称专 业 名 称提交日期2012年6月一、 问题的提出考虑在一个固定区间上用插值逼近一个函数。显然,Lagrange插值中使用的节点越多,插值多项式的次数就越高。我们自然关心插值多项式增加时,Ln(x)是否也更加靠近被逼近的函数。龙格(Runge)给出的一个例子是极著名并富有启发性的。设区间-1,1上的函数考虑区间-1,1的一个等距划分,节点为则拉格朗日插值多项式为其中的ai(x),i=0,1,2,n是n次Lagrange插值基函数。二、 实验内容研究以下三个函数在各自区间上运用不同的划分1、2、3

2、、运用在区间-p,p上等距划分(p0),节点为以x0,x1,xn为插值节点构造上述各函数的Lagrange插值多项式。运用区间a,b上切比雪夫(Chebychev)点的定义为以x1,x2,xn+1为插值节点构造上述各函数的Lagrange插值多项式,比较其结果。并分别比较两种划分方法,增加节点数,最大误差的变化。三、 实验结果及分析(一) 等距划分对于函数来说,使用等距划分其中绿色点线代表误差,红色划线代表Lagrange插值多项式,蓝色实线代表原函数。可见对于等距划分来说节点数越多,最大误差越大,可是越靠近中间的误差越少。越接近两个端点的误差越大。当节点数很大时,最大误差的来源只与靠近两个端

3、点的误差有关。例如:n=20时对于,使用等距划分当n=25时对于,使用等距划分当n=30时,从以上三个函数图像来看,可见节点越多,靠近端点处取得最大误差,并且最大误差越大。这就是龙格现象。(二) 切比雪夫(Chebychev)点首先研究 当n=20时可是当n=30同样的n=40,50也出现了两端误差增大现象。 然后研究 当n=25时同样的n=30,50也会出现龙格现象。最后研究当n=25时 此函数也不例外。由以上三个函数,通过不断改变n的值,可得运用切比雪夫点来划分,要使最大误差小于0.1,n一般取12到20间的数。(三) 综述对于Lagrange插值多项式,运用等距划分取节点时,n要不能取得

4、太大,一般n=8或8左右。若要使n取得更大,那么需要使代入到函数的点尽量在区间的中间,这样才能使真值与计算出来的值的误差尽可能的小。运用切比雪夫点来划分取节点时,n一般取12到20间的数。无论要代入到函数的点在区间的那个位置,都能使误差尽可能的小。若要使n取得更大,那么需要使代入到函数的点尽量在区间的中间,这样才能使真值与计算出来的值的误差尽可能的小。若n取的较小,同样误差也是很大的。对于以上两种取节点的方法,都不能避免龙格现象的出现。对于不同的选取节点的方法,只要n取得合适,同时代人函数的点适合,那么就可以使误差尽可能的减少。四、 关于本设计的体会为了完成本设计,接触了一个数学软件matla

5、b,并能初步运用本软件,编写程序,方便了以后对数学的研究。并且对于编写过程中遇到的错误,显示不正确等,通过网络搜索查询,能解决这些问题。例如运用fminbnd函数时,显示的并不是正确的答案,后来百度了一下,明白了此函数的运作原理,并最终能显示我想得到的结果。当然对于我所编写的程序,我也就只能做到这一步,也是碍于时间关系,和对matlab不熟悉,并不能更好的完善下去。有时取值很大时,运行起来,运行得很慢,这是一大缺陷。主要是循环次数太多,和找不到更好的函数代替所造成的。其他的缺点也就不一一的列举了。学习一个软件需要耐心,细心。多寻找,多发现,多创作才能深入了解一个软件。同样的道理,这也是做任何事

6、所需要的素质。五、 参考文献数值分析(第三版)北京理工大学出版社六、 附录所的运用软件及编号MATLAB 7.0(图略) 所用电脑的版本、型号与系统(图略)用户界面设计文件名:kcsjx.fig用户界面程序,运行kcsjx.m来调用主要程序文件名: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

7、 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 the given input arguments.% KCSJX(Property,Value,.) creates a new KCSJX or raises the% existing singleton*. Starting from the left, propert

8、y 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 GUIDEs Tools menu. Choose GUI allows only one% instance to ru

9、n (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;gui_State = struct(gui_Name, mfilename,

10、. gui_Singleton, gui_Singleton, . gui_OpeningFcn, kcsjx_OpeningFcn, . gui_OutputFcn, kcsjx_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(

11、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 has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future

12、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.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes kcsjx wait for user response

13、 (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 for returning output args (see VARARGOUT);% hObject handle to figure% eventdata reserved - to be defined i

14、n 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_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in

15、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,String) returns contents of edit1 as a doubleinput = str2num(get(hObject,String);if (isempty(input) set(hObject,String,0)endgui

16、data(hObject, handles); % - Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% 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 C

17、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 edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2

18、 (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 edit2 as text% str2double(get(hObject,String) returns contents of edit2 as a doubleinput = str2num(get(hObject,Str

19、ing); 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)% eventdata reserved - to be defined in a future version of MATLAB%

20、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,white);else set(hObject,BackgroundColor,get(0,defaultUicontrolBackgroundColor);endfunction edit3_Callback(

21、hObject, eventdata, 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 content

22、s 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 handle to edit3 (see GCBO)% eventdata res

23、erved - 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,white);else set(hObject,BackgroundColor,get(0,default

24、UicontrolBackgroundColor);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 version of MATLAB% handles structure with handles and user data (see GUIDATA)t

25、ic;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 pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2 (see GCBO)% eventdata reserved

26、- 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(str2num(t),str2num(v);toc;clear;以下为主要程序。并且可以直接在命令框调用例如:在命令框输入 kcsj(1,1,3) %代表选择等距划分,选择f(x)=1/(1+25*x2)输出结果为:以下有具体说明。主程序文件名:kcsj.mf

27、unction kcsj(t,v,n)%t为对不同x选择的判断,t=0时为等距划分,t=1时为Chebychev划分%v=1是选择f(x)=1/(1+25*x2);v=2是f(x)=x/(1+x4);v=3是f(x)=atan(x)% 函数的选取%if v=1 %题目要求不同函数,x有不同的取值范围 p=1; %x取值范围为-1,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=inl

28、ine(f); %inline为将用字符串表示的函数表达式化为函数表达式%以下为不输入n值得情况%if nargin=2 for n=2:3:17 %节点数由2至11进行循环操作 X=zeros(n+1,1); %有n+1个节点 Y=zeros(n+1,1); %对应有n+1个插值% 选择节点选取方式 % 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% 计算差值 % for i=0:n Y(i+

29、1,1)=F(X(i+1,1); end% 通过差值与节点得出Lagrange公式 % Pn=Lagrange3(X,Y); %调用拉格朗日函数进行 Ln=inline(Pn);% 计算原函数与Ln两个函数间的最大误差 % maxe=-abs(,char(Pn),-,f,); max=inline(abs(,char(Pn),-,f,); maxe=fmin(maxe,X); %调用fmin.m查找函数最小值 maxe=abs(maxe); %得出最大误差% 画出函数图像 % figure(v+t*3); %图像窗口的编号 subplot(2,3,(n+1)/3); %subplot用于在同一

30、窗口什么位置显示图像 fplot(f,-p,p,c.-); %画出原函数 if (n+1)/3)=2 %添加适当的标题 title(f,P); end hold on %多个函数在同一个图像表达 fplot(Ln,-p,p); %画出拉格朗日图像 xlabel(n=,num2str(n),最大误差=,num2str(maxe);%在x轴标注n节点的取值与最大误差 fplot(max,-p,p,r:); %画出误差图像 hold off end%以下为输入n值得情况%else if nargin=3 X=zeros(n+1,1); %有n+1个节点 Y=zeros(n+1,1); %对应有n+1

31、个插值% 选择节点选取方式 % 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% 计算差值 % for i=0:n Y(i+1,1)=F(X(i+1,1); end% 通过差值与节点得出Lagrange公式 % Pn=Lagrange3(X,Y); %调用拉格朗日函数进行 Ln=inline(Pn);% 计算原函数与Ln两个函数间的最大误差 % maxe=-abs(,char(Pn),-,f,);

32、 max=inline(abs(,char(Pn),-,f,); maxe=fmin(maxe,X); %调用fmin.m查找函数最小值 maxe=abs(maxe); %得出最大误差% 画出函数图像 % figure(v+t*3); %图像窗口的编号 subplot(1,1,1); fplot(f,-p,p,c.-); %画出原函数 title(f,P); hold on %多个函数在同一个图像表达 fplot(Ln,-p,p); %画出拉格朗日图像 xlabel(n=,num2str(n),最大误差=,num2str(maxe);% n节点的取值与最大误差 fplot(max,-p,p,r

33、:); %画出误差图像 legend(f(x)=,f,n=,num2str(n), ,P,误差); hold off endend文件名:Lagrange3.m%朗格朗日插值公式function Lg=Lagrange3(X,Y,a)syms x; %设一x的变量p=length(Y); %length为求向量元素P=0;for i=1:p z=1; for j=1:p if j=i z=z*(x-X(j)/(X(i)-X(j); end end P=P+z*double(Y(i);endif nargin=3 %nargin为输入的变量的数量的判断 digits(6); simplify(P

34、); %简化多项式 P=vpa(P) %省略分号用于输出朗格朗日插值多项式 Lg=subs(P,x,a); %用a替代变量xelse if nargin=2 P=simplify(P); %简化多项式 digits(6); P=vpa(P); Lg=P; endend文件名:fmin.mfunction fmin=fmin(f,X)min=Inf; %Inf为无穷大n=length(X); %length为求向量元素if X(1)X(2) for i=1:n-1 x,a=fminbnd(f,X(i),X(i+1); %fminbnd为在局部范围内求最函数最小值 if amin %由于fminbnd是根据导数为0来判断,有时需要缩小范围 min=a; end endelse for i=n-1:-1:1 x,a=fminbnd(f,X(i+1),X(i); %fminbnd为在局部范围内求最函数最小值 if amin %由于fminbnd是根据导数为0来判断,有时需要缩小范围 min=a; end endendfmin=min;运行时间:由于n的取值不同,和运行方式的不同,运行时间有很大的出入。在本课程设计中所运行的时间第一个按钮:最大运行时间为:13秒最小运行时间为:5秒第二个按钮一般运行时间为:20秒七、 教师评价专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 教育教学

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁