Composite Trapezoid Rule: Difference between revisions
Content added Content deleted
m (→MATLAB) |
No edit summary |
||
Line 1: | Line 1: | ||
In numerical analysis, the trapezoidal rule is used for approximation of a definite integral. The code here is a general purpose code for any equation. |
In numerical analysis, the trapezoidal rule is used for approximation of a definite integral. The code here is a general purpose code for any equation. |
||
[https://en.wikipedia.org/wiki/Trapezoidal_rule] |
|||
== MATLAB == |
== MATLAB == |
||
function integral = |
function integral = trapezoid(f, a, b, n) |
||
x = (b-a)/n; |
x = (b-a)/n; |
||
result = 0.5*f(a) + 0.5*f(b); |
result = 0.5*f(a) + 0.5*f(b); |