Lesson 11 of 18
Trapezoidal Rule
Trapezoidal Rule
Instead of rectangles, use trapezoids — connect adjacent points with line segments:
where .
Derivation
Each trapezoid has two parallel sides and and width . Its area is . Sum all trapezoids — the interior points appear twice:
Accuracy
Error is — halving reduces error by factor of 4. The trapezoidal rule is exact for linear functions.
Error Formula
For , , so on with : error .
Comparison
| Rule | Error order | Exact for |
|---|---|---|
| Left/Right | Constants | |
| Trapezoid | Linear | |
| Simpson | Cubic |
Your Task
Implement double trapezoid(double (*f)(double), double a, double b, int n).
TCC compiler loading...
Loading...
Click "Run" to execute your code.