0% found this document useful (0 votes)
5 views3 pages

TRAPIZOIDAL

The Trapezoidal Rule is a numerical integration technique that approximates the definite integral of a function over an interval by using trapezoids. The document provides the formula for the trapezoidal rule, steps for its application, and a C code implementation to compute the integral. An example is included, demonstrating how to apply the rule to approximate the integral of a specific function with given limits and subintervals.

Uploaded by

hmovies281
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

TRAPIZOIDAL

The Trapezoidal Rule is a numerical integration technique that approximates the definite integral of a function over an interval by using trapezoids. The document provides the formula for the trapezoidal rule, steps for its application, and a C code implementation to compute the integral. An example is included, demonstrating how to apply the rule to approximate the integral of a specific function with given limits and subintervals.

Uploaded by

hmovies281
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1|Page

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:

𝑓 (𝑥) 𝑑𝑥

Using the trapezoidal rule, this integral is approximated as:



𝑓 (𝑥) 𝑑𝑥 ≈ [𝑓(𝑥 ) + 2𝑓(𝑥 ) + 2𝑓(𝑥 ) + ⋯ + 2𝑓(𝑥 ) + 𝑓(𝑥 )]
2
Where:
 𝑥 = 𝑎, 𝑥 = 𝑏,
 ℎ= is the width of each subinterval,
 𝑛 is the number of subintervals,
 𝑥 ,𝑥 ,…,𝑥 are the intermediate points.
Steps
1. Divide the interval [𝑎, 𝑏] into 𝑛 equal subintervals.
2. Compute the function values at 𝑥 , 𝑥 , … , 𝑥 .
3. Apply the formula to calculate the approximate integral.

C Code for Trapezoidal Rule


Here is the implementation of the trapezoidal rule in C:
#include <stdio.h>
#include <math.h>

// Define the function f(x) to integrate


double f(double x) {
return 1 / (1 + x * x); // Example: Function f(x) = 1 / (1 + x^2)
}

int main() {
double a, b, h, result = 0.0;
int n, i;

// Input the limits of integration and number of subintervals


printf("Enter the lower limit of integration (a): ");
2|Page

scanf("%lf", &a);
printf("Enter the upper limit of integration (b): ");
scanf("%lf", &b);
printf("Enter the number of subintervals (n): ");
scanf("%d", &n);

// Calculate the step size


h = (b - a) / n;

// Apply the Trapezoidal Rule


for (i = 0; i <= n; i++) {
double x = a + i * h;
if (i == 0 || i == n) {
result += f(x); // First and last terms
} else {
result += 2 * f(x); // Middle terms
}
}

// Final result
result = (h / 2) * result;

// Output the result


printf("\nThe approximate value of the integral is: %.6f\n", 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 function is evaluated at points 𝑥 , 𝑥 , … , 𝑥 .


o The first and last terms are added directly, while the intermediate terms are multiplied by 2 and
summed.
5. Result:

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy