#小舞的个人笔记#
梯形法和辛普森法的matlab实例及误差曲线
一、求积分
1.递增函数y=x^4在[0,1]的积分
(1)梯形法
%y = x^4
k = 3;
n = 2^k;
a = 0;
b = 1;
h = (b-a)/n;
m = 0;
S = 0;
while(m<n)
S = S+(a+m*h)^4;
m = m+1;
end
f = h*0.5*(a^4+2*S+b^4);
fprintf('梯形法算得的积分为 %.5f',f);
(2)辛普森法
%y = x^4
k = 3;
n = 2^k;
a = 0;
b = 1;
h = (b-a)/n;
m1 = 0.5;
m2 = 1;
S = 0;
K = 0;
while(m1<n)
S = S+(a+m1*h)^4;
m1 = m1+1;
end
while(m2<n)
K = K+
版权声明:本文为qq_50750032原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。