Let’s understand the trapezoidal method in numerical analysis and implement trapezoidal rule in C programming language.
What is Trapezoidal Rule?
This numerical analysis method is used to approximating the definite integral. The trapezoidal numerical method works on the principle of straight line approximation.
This numerical method is also popularly known as Trapezoid Rule or Trapezium Rule.
This numerical analysis method is slower in convergence as compared to Simpson’s rule in numerical method.
Trapezium Rule Formula
This is a technique to approximate the definite integrals. It approximates the region under the graph of the function f(x) and calculates its area.
This method becomes more accurate and outputs perfect results when periodic functions are integrated over their periods.
Note: This C program to solve trapezoidal rule is compiled with GNU GCC compiler on Linux Ubuntu operating system. However, this code is compatible with all other operating systems.
If you try to compile this C program for Trapezium Rule in Linux, you will get the following error:
This is because the pow() method cannot be found in the library files. To overcome this error, you will have to explicitly include the math.h header file.
Compile the program using the following command:
C Program To Implement Trapezoidal Rule using Function
If you have any doubts about the implementation of Trapezoidal method in C programming, let us know about it in the comment section. Find more about it on Wikipedia.