定积分的近似运算
一.单调增函数
(1)y=x^2
矩形法inum1 =0.328350000000000 inum2 = 0.338350000000000
inum3 =0.333325000000000
integrate =1/3 integrate = 0.333333333333333
the relative error between inum1 and real-value is about: 0.01495
the relative error between inum2 and real-value is about: 0.01505
the relative error between inum3 and real-value is about: 2.5e-05
梯形法inum =0.333350000000000 integrate =1/3
the relative error between inum1 and real-value is about: 0.0199
the relative error between inum2 and real-value is about: 0.0201
the relative error between inum3 and real-value is about: 5e-05
fx1=subs(fx,x,x1);
fx2=subs(fx,x,x2);
si=(fx0+4*fx1+fx2)*(b-a)/(6*n);
inum=inum+si;
end
inum
integrate=int(fx,0,1);
integrate=double(integrate)
fprintf('抛物线法的相对误差为:%e\n',abs((inum-integrate)/integrate))您的朋友周园园为这封邮件插入了背景音乐-下载播放
实验所用软件及版本点):
1.用矩形法、梯形法和抛物线法分别计算单调增函数、单调减函数、凸函数和凹函数在某个区间上的定积分。
(1)每类函数三个以上
(2)总结对同一类函数,用哪种方法近似结果更好
(3)与Matlab中的各个命令作比较
实验过程记录(含基本步骤、主要程序清单及异常情况记录等):
数学实验报告
实验序号:3日期:2014年12月16日
班级
应数二班
姓名
方婷
学号
1201114018
实验名称
定积分的近似计算
问题背景描述:
定积分计算的基本公式是牛顿-莱布尼兹公式。但当被积函数的原函数不知道时,如何计算?这时就需要利用近似计算。特别是在许多实际应用中,被积函数甚至没有解析表达式,而是一条实验记录曲线,或一组离散的采样值,此时只能用近似方法计算定积分。
(2) y=x+1
(3)y=x.^3
二.单调减函数
(1)y=1/x
(2)y=-x+1
(3)y=1/(1+x.^2)
三.单调凸函数
(1)y=x.^4
(2)y=x^2
(3)y=exp(x)
四.单调凹函数
(1)y=-x^2
(2)y=-x.^3+1
(3)y=sin(x)
以上函数三种方法与单调增函数(1)同
实验结果报告与实验总结:
inum
integrate=int(fx,0,1)
integrate=double(integrate)
fprintf('the relative error between inum and real-value is about: %g\n\n',...
abs((inum-integrate)/integrate))
integrate = 0.333333333333333
the relative error between inum and real-value is about: 5e-05
抛物线法inum =0.333333333333333 integrate =0.333333333333333
抛物线法的相对误差为:1.665335e-16
矩形法inum1 = 0.505000000000000 inum2 =0.495000000000000
inum3 =0.500000000000000
integrate =1/2 integrate = 0.500000000000000
the relative error between inum1 and real-value is about: 0.01
fxij=subs(fx,'x',(xi+xj)/2);
inum1=inum1+fxj*(b-a)/n;
inum2=inum2+fxi*(b-a)/n;
inum3=inum3+fxij*(b-a)/n;
end
inum1
inum2
inum3
integrate=int(fx,0,1)
integrate=double(integrate)
(3)中点法:同(1)中划分区间,在区间 上取中点,即取 。
2.梯形法
等分区间 ,
相应函数值为 ( )。曲线 上相应的点为 ( ),将曲线的每一段弧 用过点 , 的弦 (线性函数)来代替,这使得每个 上的曲边梯形成为真正的梯形,其面积为,
.
于是各个小梯形面积之和就是曲边梯形面积的近似值, ,即 ,称此式为梯形公式。
the relative error between inum2 and real-value is about: 0.00333333
the relative error between inum3 and real-value is about: 1.4803e-16
梯形法inum =1.500000000000000 integrate =3/2
抛物线法
formatlong
n=100;
a=0;b=1;
inum=0;
symsxfx
fx=x^2;
fori=1:n
x0=a+(2*i-2)*(b-a)/(2*n);
x1=a+(2*i-1)*(b-a)/(2*n);
x2=a+(2*i-0)*(b-a)/(2*n);
fx0=subs(fx,x,x0);
n=100;a=0;b=1;
inum=0;
symsxfx
fx=x^2;
fori=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);
inum=inum+(fxj+fxi)*(b-a)/(2*n);
end
本实验主要研究定积分的三种近似计算算法:矩形法、梯形法和抛物线法。同时介绍Matlab
算定积分的相关函数。
实验目的:
本实验主要研究定积分的三种近似计算算法:矩形法、梯形法和抛物线法。同时介绍Matlab
算定积分的相关函数
实验原理与数学模型:
1.矩形法定积分的定义:根据定积分的定义,每一个积分和都可以看作是定积分的一个近似值 。
fprintf('the relative error between inum1 and real-value is about: %g\n\n',...
abs((inum1-integrate)/integrate))
fprintf('the relative error between inum2 and real-value is about: %g\n\n',...
integrate =0.250000000000000
抛物线法的相对误差为:2.220446e-16
二.单调减函数
(1)y=1/x
矩形法inum1 = Inf inum2 =5.187377517639621
inum3 =6.568684378603265 integrate =Inf integrate =Inf
梯形法inum =0.250025000000000 integrate =1/4
integrate =0.250000000000000
the relative error between inum and real-value is about: 0.0001
抛物线法inum =0.250000000000000
一.单调增函数
(1)y=x^2
矩形法
formatlong
n=100;a=0;b=1;
inum1=0;inum2=0;inum3=0;
symsxfx
fx=x^2;
fori=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);
abs((inum2-integrate)/integrate))
fprintf('the relative error between inum3 and real-value is about: %g\n\n',...
abs((inum3-integrate)/integrate))
梯形法
formatlong
(2) y=x+1
矩形法inum1 =1.495000000000000 inum2 =1.505000000000000