Simpsons 1/3 Rule C Program
Simpsons 1/3 Rule C Program
Let’s understand the Simpson’s 1/3rd rule method in numerical analysis and implement Simpsons
1/3 rule in C programming language.
The Simpson’s 1/3rd rule is used in numerical integration. Integration is the process of measuring
the area under a function plotted on a graph. The Simpson’s 1/3rd rule was developed by a
mathematician named Thomas Simpson.
The Simpson’s 1/3rd integration method is primarily used for numerical approximation of definite
integrals. This specifically means that Simpson’s integration rule is used in complex integration
calculations.
It is a method to approximately calculate the definite integral. The Simpson’s theorem is used to
find the area under a given curve. The Simpson’s method corresponds to the 3-point Newton-
Cotes quadrature rule as well.
The Simpson’s integration method is a little time consuming compared to other methods in
numerical analysis and is also a little difficult to implement computationally.
Step 1: Input Values For Lower Boundary, Upper Boundary and Width
Step 2: Calculate value for the formula: value = (upper_boundary - lower_boundary) / width
Step 3: Compute Width with this formula: width = (upper_boundary - lower_boundary) / value
Step 4: Consider y = f(x). Calculate the values of Y(Lower Bound to Upper Bound)
Step 5: Substitute the above values in the Simpsons 1/3 Rule Formula
Note: This C Program for Simpson’s 1/3 rule is compiled with GNU GCC compiler on CodeLite
IDE. However, it is compatible with all other operating systems.
Method 1: C Program For Simpson’s 1/3rd Rule using Function
include<stdio.h>
int main()
scanf("%f", &lower_boundary);
scanf("%f", &upper_boundary);
scanf("%f", &width);
if(value % 2 == 1)
{ value = value + 1;
printf("\nModified Values:\n");
printf("\nWidth:\t%f\n", width);
printf("\nY values\n");
count++;
count = 1;
{ if(count % 2 == 1)
m = m + y[count];
else
{ n = n + y[count];
count++; }
return 0;}
{ return(1 / (1 + temp));
}
Trapezoidal Rule C Program
Let’s understand the trapezoidal method in numerical analysis and implement trapezoidal rule in C
programming language.
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.
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.
C Program To Implement Trapezoidal Rule using Function
#include<stdio.h>
#include<math.h>
float trapezoidal_rule(float x)
{ return sqrt(x);
int main()
scanf("%d", &interval);
scanf("%f", &lower_limit);
scanf("%f", &upper_limit);
}
result = (trapezoidal_rule(lower_limit) + trapezoidal_rule(upper_limit) + 2*sum)
* (length/2);
return 0;
Output