Skip to main content

INTEGRAL (TRAPEZOIDAL RULE)


## This m-file computes the integral of a function f over the
## equally spaced points x using the trapezoidal rule.
function I = trapezoid(x,f)
h = x(2)-x(1);
N = length(f);
I = 0;
for n=2:N-1,
I = I + h*f(n);
endfor
I = I + h/2*(f(1) + f(N));
endfunction

Comments

Popular posts from this blog