Composite Trapezoid Rule: Difference between revisions
Content added Content deleted
No edit summary |
m (→MATLAB) |
||
Line 5: | Line 5: | ||
function integral = trapezoidal(f, a, b, n) |
function integral = trapezoidal(f, a, b, n) |
||
x = (b-a)/n; |
|||
result = 0.5*f(a) + 0.5*f(b); |
result = 0.5*f(a) + 0.5*f(b); |
||
for i = 1:(n-1) |
for i = 1:(n-1) |
||
result = result + f(a + i* |
result = result + f(a + i*x); |
||
end |
end |
||
integral = |
integral = x*result; |
||
end |
end |
||