matlab实验报告定积分的近似计算说明.doc

上传人:doc321 文档编号:14839370 上传时间:2022-02-20 格式:DOC 页数:12 大小:131KB
返回 下载 相关 举报
matlab实验报告定积分的近似计算说明.doc_第1页
第1页 / 共12页
matlab实验报告定积分的近似计算说明.doc_第2页
第2页 / 共12页
matlab实验报告定积分的近似计算说明.doc_第3页
第3页 / 共12页
matlab实验报告定积分的近似计算说明.doc_第4页
第4页 / 共12页
matlab实验报告定积分的近似计算说明.doc_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《matlab实验报告定积分的近似计算说明.doc》由会员分享,可在线阅读,更多相关《matlab实验报告定积分的近似计算说明.doc(12页珍藏版)》请在三一文库上搜索。

1、数学实验报告实验序号:2 日期:2013 年11 月 30日 班级应数二班姓名丁慧娜学号1101114088 实验名称定积分的近似计算实验所用软件及版本MATLAB R2012b问题背景描述:利用牛顿莱布尼兹公式虽然可以精确地计算定积分的值,但它仅适用于被积函数的原函数能用初等函数表达出来的情形如果这点办不到或者不容易办到,这就有必要考虑近似计算的方法在定积分的很多应用问题中,被积函数甚至没有解析表达式,可能只是一条实验记录曲线,或者是一组离散的采样值,这时只能应用近似方法去计算相应的定积分实验目的:1、 本实验将主要研究定积分的三种近似计算算法:矩形法、梯形法、抛物线法。2、 加深理解积分运

2、算中分割、近似、求和、取极限的思想方法。3、 学习fulu2sum.m的程序设计方法,尝试用函数 sum 改写附录1和附录3的程序,避免for 循环。实验原理与数学模型:1 矩形法根据定积分的定义,每一个积分和都可以看作是定积分的一个近似值,即在几何意义上,这是用一系列小矩形面积近似小曲边梯形的结果,所以把这个近似计算方法称为矩形法不过,只有当积分区间被分割得很细时,矩形法才有一定的精确度针对不同的取法,计算结果会有不同。(1) 左点法:对等分区间,在区间上取左端点,即取。(2)右点法:同(1)中划分区间,在区间上取右端点,即取。(3)中点法:同(1)中划分区间,在区间上取中点,即取。2 梯形

3、法等分区间,相应函数值为 ()曲线上相应的点为 ()将曲线的每一段弧用过点,的弦(线性函数)来代替,这使得每个上的曲边梯形成为真正的梯形,其面积为,于是各个小梯形面积之和就是曲边梯形面积的近似值,即 ,称此式为梯形公式。3 抛物线法将积分区间作等分,分点依次为,对应函数值为(),曲线上相应点为()现把区间上的曲线段用通过三点,的抛物线来近似代替,然后求函数从到的定积分:由于,代入上式整理后得同样也有将这个积分相加即得原来所要计算的定积分的近似值:,即这就是抛物线法公式,也称为辛卜生(Simpson)公式主要内容(要点):1 分别用梯形法与抛物线法,计算,取并尝试直接使用函数trapz()、qu

4、ad()进行计算求解,比较结果的差异2 试计算定积分(注意:可以运用trapz()、quad()或附录程序求解吗?为什么?)3 学习fulu2sum.m的程序设计方法,尝试用函数 sum 改写附录1和附录3的程序,避免for 循环。实验过程记录(含基本步骤、主要程序清单及异常情况记录等):1:梯形法format longn=120;a=1;b=2;syms x fxfx=1/x;i=1:n;xj=a+(i-1)*(b-a)/n; %所有左点的数组xi=a+i*(b-a)/n; %所有右点的数组fxj=subs(fx,x,xj); %所有左点值fxi=subs(fx,x,xi); %所有右点值f

5、=(fxi+fxj)/2*(b-a)/n; %梯形面积inum=sum(f) %加和梯形面积求解integrate=int(fx,1,2);integrate=double(integrate)fprintf(The relative error between inum and real-value is about:%g/n/n,.abs(inum-integrate)/integrate)【调试结果】TXFinum = 0.693151520800048integrate = 0.693147180559945The relative error between inum and rea

6、l-value is about:6.26164e-06/n/n 抛物线法:%抛物线法format longn=120;a=1;b=2;inum=0;syms x fxfx=1/x;for i=1:n xj=a+(i-1)*(b-a)/n; %左点 xi=a+i*(b-a)/n; %右点 xk=(xi+xj)/2; %中点 fxj=subs(fx,x,xj); fxi=subs(fx,x,xi); fxk=subs(fx,x,xk); inum=inum+(fxj+4*fxk+fxi)*(b-a)/(6*n);endinumintegrate=int(fx,1,2);integrate=dou

7、ble(integrate);fprintf(The relative error between inum and real-value is about:%g/n/n,.abs(inum-integrate)/integrate)【调试结果】 clear PWXFinum = 0.693147180569364The relative error between inum and real-value is about:1.35886e-11/n/n 使用函数trapz()x=1:1/120:2;y=1./x;trapz(x,y)【调试结果】ans = 0.69315152080005使用

8、函数quad()quad(1./x,1,2)【调试结果】ans = 0.693147199862972:使用函数trapz()x=1:1/120:inf;y=sin(x)./x;trapz(x,y)【调试结果】? Error using = colonMaximum variable size allowed by the program is exceeded.使用函数quad()quad(sin(x)./x,0,inf)【调试结果】ans = NaN程序法%矩阵法format longn=inf;a=0;b=inf;syms x fxfx=sin(x)./x;i=1:n;xj=a+(i-1

9、)*(b-a)/n; %左点xi=a+i*(b-a)/n; %右点xij=(xi+xj)/2;fxj=subs(fx,x,xj); %左点值fxi=subs(fx,x,xi); %右点值fxij=subs(fx,x,xij); %中点值f1=fxj*(b-a)/n;f2=fxi*(b-a)/n;f3=fxij*(b-a)/n;inum1=sum(f1)inum2=sum(f2)inum3=sum(f3)integrate=int(fx,0,inf);integrate=double(integrate);fprintf(the relative error between inum1 and

10、real-value is about: %gnn,. abs(inum1-integrate)/integrate)fprintf(the relative error between inum2 and real-value is about: %gnn,. abs(inum2-integrate)/integrate)fprintf(the relative error between inum3 and real-value is about: %gnn,.abs(inum3-integrate)/integrate)【调试结果】Maximum variable size allowe

11、d by the program is exceeded.Error in CXF (line 6)i=1:n;使用matlab命令syms x;f=sin(x)/x;I=int(f,0,inf)【调试结果】I = 1/2*pi3:矩形法:利用求和函数%矩阵法format longn=100;a=0;b=1;syms x fxfx=1/(1+x2);i=1:n;xj=a+(i-1)*(b-a)/n; %左点xi=a+i*(b-a)/n; %右点xij=(xi+xj)/2;fxj=subs(fx,x,xj); %左点值fxi=subs(fx,x,xi); %右点值fxij=subs(fx,x,x

12、ij); %中点值f1=fxj*(b-a)/n;f2=fxi*(b-a)/n;f3=fxij*(b-a)/n;inum1=sum(f1)inum2=sum(f2)inum3=sum(f3)integrate=int(fx,0,1);integrate=double(integrate);fprintf(the relative error between inum1 and real-value is about: %gnn,. abs(inum1-integrate)/integrate)fprintf(the relative error between inum2 and real-va

13、lue is about: %gnn,. abs(inum2-integrate)/integrate)fprintf(the relative error between inum3 and real-value is about: %gnn,.abs(inum3-integrate)/integrate)【调试结果】 txfinum1 = 0.787893996730782inum2 = 0.782893996730782inum3 = 0.785400246730781the relative error between inum1 and real-value is about: 0.

14、00317779the relative error between inum2 and real-value is about: 0.0031884the relative error between inum3 and real-value is about: 2.65258e-06 抛物线法:使用求和函数%抛物线format longn=100;a=0;b=1;syms x fxfx=1/(1+x2);i=1:n;xj=a+(i-1)*(b-a)/n; %左点xi=a+i*(b-a)/n; %右点xij=(xi+xj)/2;fxj=subs(fx,x,xj); %左点值fxi=subs(

15、fx,x,xi); %右点值fxij=subs(fx,x,xij); %中点值f=(fxj+4*fxij+fxi)*(b-a)/(6*n);inum=sum(f)integrate=int(fx,0,1);integrate=double(integrate);fprintf(the relative error between inum and real-value is about: %gnn,. abs(inum-integrate)/integrate)【调试结果】 pwxf2inum = 0.785398163397448the relative error between inum

16、 and real-value is about: 2.82716e-16【情况记录】1、刚开始使用函数trapz(),quad()时没注意被积函数是数值形式,总是出错,应使用数组计算,应用点除即 ./ ,否则将出错,不能调试出结果。2、使用函数trapz(),quad()和附录程序求解时,很难理解题意,运算的时候容易弄错,不能调试出获得出正确答案。最后尝试用matlab命令中的符号求积分才得出正确结果。3、了解了矩形法、梯形法、抛物线法的计提方法。参照附录B中的求和函数程序设计顺利改变了附录A和C。发现使用求和函数时,inum不需要赋初值,应用了积分理论中分割、近似、求和、取极限的思想方法,

17、避免了for循环的冗杂性,较容易理解。实验结果报告及实验总结:1、结果梯形法inum = 0.69315152080005integrate = 0.69314718055995The relative error between inum and real-value is about:6.26164e-006/n/n抛物线法:inum = 0.69314718056936The relative error between inum and real-value is about:1.35886e-011/n/n使用函数trapz()ans =0.69315152080005使用函数qua

18、d()ans =0.69314719986297将题中的近似计算结果与Matlab各命令的计算结果相比较,发现运用不同的方法,计算结果会有不同。因为由梯形法求近似值,当为凹曲线时,它就偏小;当为凸曲线时,它就偏大误差较大。故由计算结果知,利用抛物线法近似计算定积分,更接近于实际值,精确程度更高且发现trapz()的调试结果与梯形法结果相同,故可猜测该Matlab中的数值积分命令函数trapz()采用了梯形法近似计算方法。2、使用函数trapz()? Error using = colonMaximum variable size allowed by the program is exceed

19、ed.使用函数quad()ans = NaN程序法? Maximum variable size allowed by the program is exceeded.使用matlab命令I =1/2*pi通过实验发现使用函数trapz(),quad()和附录程序求解,均不能调试出或得出正确答案。用matlab命令中的符号求积分int()才得出正确结果。故矩形法、梯形法、抛物线法是主要研究定积分的三种近似计算算法。Matlab的专门函数trapz(),quad()也是用于定积分的近似数值计算。对于不定积分,由于积分区间无限大,故不能使用该分割方法。3、实验结果见实验过程中的调试结果。调试顺利。使用sum函数时,inum不需要赋初值,应用了积分理论中分割近似求和取极限的思想方法,避免了for循环的冗杂性,简单明了。思考与深入:通过本实验深刻理解了不定积分、定积分概念,熟悉了Matlab数学软件的求不定积分、定积分的命令,了解简单的编程语句。加深理解了积分理论中分割、近似、求和、取极限的思想方法。学习并掌握了用Matlab求定积分的方法,了解了定积分近似计算的矩形法、梯形法,和抛物线法。并认识到对于不同的题目,采取不同的运算方法,结果会不同,且精确程度也不同。教师评语:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1