TRAPIZOIDAL
TRAPIZOIDAL
Trapezoidal rule
Theory of Trapezoidal Rule
The Trapezoidal Rule is a numerical integration technique used to approximate the definite integral of a
function 𝑓(𝑥) over an interval [𝑎, 𝑏]. The idea is to approximate the region under the curve by a series of
trapezoids, calculate their areas, and sum them up.
Formula
For a function 𝑓(𝑥), the definite integral from 𝑎 to 𝑏 is:
𝑓 (𝑥) 𝑑𝑥
int main() {
double a, b, h, result = 0.0;
int n, i;
scanf("%lf", &a);
printf("Enter the upper limit of integration (b): ");
scanf("%lf", &b);
printf("Enter the number of subintervals (n): ");
scanf("%d", &n);
// Final result
result = (h / 2) * result;
return 0;
}
Example
Input
Enter the lower limit of integration (a): 0
Enter the upper limit of integration (b): 1
Enter the number of subintervals (n): 6
Output
The approximate value of the integral is: 0.783611
Explanation
1. Function Used:
o The function 𝑓(𝑥) = is integrated. This function is related to the integral of tan (𝑥), and
the exact integral from 0 to 1 is ≈ 0.785398.
2. Inputs:
o Lower limit 𝑎 = 0,
o Upper limit 𝑏 = 1,
3|Page
o Subintervals 𝑛 = 6.
3. Step Size:
o ℎ= = = 0.1667.
4. Trapezoidal Rule Application:
o The integral is approximated as 0.783611, which is close to the exact value of 0.785398.
This demonstrates how the trapezoidal rule effectively approximates definite integrals with simplicity and
reasonable accuracy.