⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trapezoid.m

📁 D:matlab mmintegrate.rar数值积分
💻 M
字号:
function I = trapezoid(fun,a,b,npanel)
% trapezoid  Composite trapezoid rule
%
% Synopsis:  I = trapezoid(fun,a,b,npanel)
%
% Input:     fun    = (string) name of m-file that evaluates f(x)
%            a, b   = lower and upper limits of the integral
%            npanel = number of panels to use in the integration
%                     Total number of nodes = npanel + 1
%
% Output:    I = approximate value of the integral from a to b of f(x)*dx

n = npanel + 1;      %  total number of nodes
h = (b-a)/(n-1);     %  stepsize
x = a:h:b;           %  divide the interval
f = feval(fun,x);    %  evaluate integrand

I = h * ( 0.5*f(1) + sum(f(2:n-1)) + 0.5*f(n) );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -