matlab中几种求积分的方法举例图形Midpoint RuleTrapezoid Rule13 Simpsons利用integral结果显示
最近看了几天matlab的基础知识,总结一下求简单积分的方法
fi = f((x1 + x2) / 2) 取两点之间中点的平均值作为该区域的高
h = pi/100;x = 0:h:2*pi;mid = (x(1:end-1) + x(2:end)) / 2;y = sin(x) + cos(x);s1 = h * sum(y)fi = (f(x1) + f(x2)) / 2; 取两点函数值得平均值作为该区域的高
h = pi/100;x = 0:h:2*pi;y = sin(x) + cos(x);yy = (y(1:end-1) + y(2:end))/2;s2 = h * sum(yy)除此以外,matlab中的trapz函数可用来调用求其值,如下
h = pi/100;x = 0:h:2*pi;y = sin(x) + cos(x);s3 = h * trapz(y)fi = 3/h*(f0 + 4f1 + f2),利用公式求解即可
h = pi/100;x = 0:h:2*pi;y = sin(x) + cos(x);s4 = h * (y(1) + y(end) + 2*sum(y(3:2:end-2)) + 4*sum(y(2:2:end-1)))对比一下各种方式求出的积分值
新闻热点
疑难解答